@vitia.ai/secure-api-client-vue 1.0.20 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
${e.join(`
|
|
62
62
|
`)}`:`${t} :`}}Lt=te;d.Constructed=Lt;te.NAME="CONSTRUCTED";class Rt extends x{fromBER(e,t,r){return t}toBER(e){return _}}Rt.override="EndOfContentValueBlock";var Mt;class Ot extends A{constructor(e={}){super(e,Rt),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}Mt=Ot;d.EndOfContent=Mt;Ot.NAME=he;var Dt;class $t extends A{constructor(e={}){super(e,x),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,r){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=r,t+r>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+r}toBER(e,t){const r=new ArrayBuffer(2);if(!e){const s=new Uint8Array(r);s[0]=5,s[1]=0}return t&&t.write(r),r}onAsciiEncoding(){return`${this.constructor.NAME}`}}Dt=$t;d.Null=Dt;$t.NAME="NULL";class Pt extends M(x){get value(){for(const e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=B.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,r){const s=B.toUint8Array(e);return R(this,s,t,r)?(this.valueHexView=s.subarray(t,t+r),r>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,pt.call(this),this.blockLength=r,t+r):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}}Pt.NAME="BooleanValueBlock";var Ft;class jt extends A{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Pt),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}}Ft=jt;d.Boolean=Ft;jt.NAME="BOOLEAN";class qt extends M(F){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,r){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=F.prototype.fromBER.call(this,e,t,r),s===-1)return s;for(let i=0;i<this.value.length;i++){const o=this.value[i].constructor.NAME;if(o===he){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(o!==Et)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(e,t,r),this.blockLength=r;return s}toBER(e,t){return this.isConstructed?F.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}}qt.NAME="OctetStringValueBlock";var Me;class Gt extends A{constructor({idBlock:e={},lenBlock:t={},...r}={}){var s,i;(s=r.isConstructed)!==null&&s!==void 0||(r.isConstructed=!!(!((i=r.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},qt),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,r){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,r===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){const i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+r);try{if(i.byteLength){const o=Be(i,0,i.byteLength);o.offset!==-1&&o.offset===r&&(this.valueBlock.value=[o.result])}}catch{}}return super.fromBER(e,t,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return te.prototype.onAsciiEncoding.call(this);const e=this.constructor.NAME,t=v.ToHex(this.valueBlock.valueHexView);return`${e} : ${t}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;const e=[];for(const t of this.valueBlock.value)t instanceof Me&&e.push(t.valueBlock.valueHexView);return B.concat(e)}}Me=Gt;d.OctetString=Me;Gt.NAME=Et;class Jt extends M(F){constructor({unusedBits:e=0,isConstructed:t=!1,...r}={}){super(r),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,r){if(!r)return t;let s=-1;if(this.isConstructed){if(s=F.prototype.fromBER.call(this,e,t,r),s===-1)return s;for(const a of this.value){const c=a.constructor.NAME;if(c===he){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Nt)return this.error="BIT STRING may consists of BIT STRINGs only",-1;const l=a.valueBlock;if(this.unusedBits>0&&l.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=l.unusedBits}return s}const i=B.toUint8Array(e);if(!R(this,i,t,r))return-1;const o=i.subarray(t,t+r);if(this.unusedBits=o[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){const a=o.subarray(1);try{if(a.byteLength){const c=Be(a,0,a.byteLength);c.offset!==-1&&c.offset===r-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,t+r}toBER(e,t){if(this.isConstructed)return F.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength){const s=new Uint8Array(1);return s[0]=0,s.buffer}const r=new Uint8Array(this.valueHexView.length+1);return r[0]=this.unusedBits,r.set(this.valueHexView,1),r.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}}Jt.NAME="BitStringValueBlock";var Kt;class Oe extends A{constructor({idBlock:e={},lenBlock:t={},...r}={}){var s,i;(s=r.isConstructed)!==null&&s!==void 0||(r.isConstructed=!!(!((i=r.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},Jt),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,r){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return te.prototype.onAsciiEncoding.call(this);{const e=[],t=this.valueBlock.valueHexView;for(const o of t)e.push(o.toString(2).padStart(8,"0"));const r=e.join(""),s=this.constructor.NAME,i=r.substring(0,r.length-this.valueBlock.unusedBits);return`${s} : ${i}`}}}Kt=Oe;d.BitString=Kt;Oe.NAME=Nt;var Wt;function Vs(n,e){const t=new Uint8Array([0]),r=new Uint8Array(n),s=new Uint8Array(e);let i=r.slice(0);const o=i.length-1,a=s.slice(0),c=a.length-1;let l=0;const f=c<o?o:c;let h=0;for(let u=f;u>=0;u--,h++){switch(!0){case h<a.length:l=i[o-h]+a[c-h]+t[0];break;default:l=i[o-h]+t[0]}switch(t[0]=l/10,!0){case h>=i.length:i=Ne(new Uint8Array([l%10]),i);break;default:i[o-h]=l%10}}return t[0]>0&&(i=Ne(t,i)),i}function ot(n){if(n>=oe.length)for(let e=oe.length;e<=n;e++){const t=new Uint8Array([0]);let r=oe[e-1].slice(0);for(let s=r.length-1;s>=0;s--){const i=new Uint8Array([(r[s]<<1)+t[0]]);t[0]=i[0]/10,r[s]=i[0]%10}t[0]>0&&(r=Ne(t,r)),oe.push(r)}return oe[n]}function _s(n,e){let t=0;const r=new Uint8Array(n),s=new Uint8Array(e),i=r.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1;let l,f=0;for(let h=c;h>=0;h--,f++)switch(l=i[o-f]-a[c-f]-t,!0){case l<0:t=1,i[o-f]=l+10;break;default:t=0,i[o-f]=l}if(t>0)for(let h=o-c+1;h>=0;h--,f++)if(l=i[o-f]-t,l<0)t=1,i[o-f]=l+10;else{t=0,i[o-f]=l;break}return i.slice()}class De extends M(x){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=pt.call(this)))}constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Es(e))}get valueDec(){return this._valueDec}fromDER(e,t,r,s=0){const i=this.fromBER(e,t,r);if(i===-1)return i;const o=this.valueHexView;return o[0]===0&&o[1]&128?this.valueHexView=o.subarray(1):s!==0&&o.length<s&&(s-o.length>1&&(s=o.length+1),this.valueHexView=o.subarray(s-o.length)),i}toDER(e=!1){const t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{const r=new Uint8Array(this.valueHexView.length+1);r[0]=0,r.set(t,1),this.valueHexView=r}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,r){const s=super.fromBER(e,t,r);return s===-1||this.setValueHex(),s}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){const e=this.valueHexView.length*8-1;let t=new Uint8Array(this.valueHexView.length*8/3),r=0,s;const i=this.valueHexView;let o="",a=!1;for(let c=i.byteLength-1;c>=0;c--){s=i[c];for(let l=0;l<8;l++){if((s&1)===1)switch(r){case e:t=_s(ot(r),t),o="-";break;default:t=Vs(t,ot(r))}r++,s>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(o+=it.charAt(t[c]));return a===!1&&(o+=it.charAt(0)),o}}Wt=De;De.NAME="IntegerValueBlock";Object.defineProperty(Wt.prototype,"valueHex",{set:function(n){this.valueHexView=new Uint8Array(n),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var le;class $e extends A{constructor(e={}){super(e,De),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return we(),BigInt(this.valueBlock.toString())}static fromBigInt(e){we();const t=BigInt(e),r=new Le,s=t.toString(16).replace(/^-/,""),i=new Uint8Array(v.FromHex(s));if(t<0){const a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;const l=BigInt(`0x${v.ToHex(a)}`)+t,f=B.toUint8Array(v.FromHex(l.toString(16)));f[0]|=128,r.write(f)}else i[0]&128&&r.write(new Uint8Array([0])),r.write(i);return new le({valueHex:r.final()})}convertToDER(){const e=new le({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new le({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}le=$e;d.Integer=le;$e.NAME="INTEGER";var Xt;class Zt extends $e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}Xt=Zt;d.Enumerated=Xt;Zt.NAME="ENUMERATED";class Ie extends M(x){constructor({valueDec:e=-1,isFirstSid:t=!1,...r}={}){super(r),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,r){if(!r)return t;const s=B.toUint8Array(e);if(!R(this,s,t,r))return-1;const i=s.subarray(t,t+r);this.valueHexView=new Uint8Array(r);for(let a=0;a<r&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);const o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Q(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){we();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;const r=new Uint8Array(t.length/7);for(let s=0;s<r.length;s++)r[s]=parseInt(t.slice(s*7,s*7+7),2)+(s+1<r.length?128:0);this.fromBER(r.buffer,0,r.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}const t=J(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",_;const r=new Uint8Array(t.byteLength);if(!e){const s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)r[o]=s[o]|128;r[i]=s[i]}return r}toString(){let e="";if(this.isHexOnly)e=v.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}}Ie.NAME="sidBlock";class zt extends x{constructor({value:e=ee,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let s=t;for(;r>0;){const i=new Ie;if(s=i.fromBER(e,s,r),s===-1)return this.blockLength=0,this.error=i.error,s;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,r-=i.blockLength,this.value.push(i)}return s}toBER(e){const t=[];for(let r=0;r<this.value.length;r++){const s=this.value[r].toBER(e);if(s.byteLength===0)return this.error=this.value[r].error,_;t.push(s)}return He(t)}fromString(e){this.value=[];let t=0,r=0,s="",i=!1;do if(r=e.indexOf(".",t),r===-1?s=e.substring(t):s=e.substring(t,r),t=r+1,i){const o=this.value[0];let a=0;switch(o.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}const c=parseInt(s,10);if(isNaN(c))return;o.valueDec=c+a,i=!1}else{const o=new Ie;if(s>Number.MAX_SAFE_INTEGER){we();const a=BigInt(s);o.valueBigInt=a}else if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return;this.value.length||(o.isFirstSid=!0,i=!0),this.value.push(o)}while(r!==-1)}toString(){let e="",t=!1;for(let r=0;r<this.value.length;r++){t=this.value[r].isHexOnly;let s=this.value[r].toString();r!==0&&(e=`${e}.`),t?(s=`{${s}}`,this.value[r].isFirstSid?e=`2.{${s} - 80}`:e+=s):e+=s}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}zt.NAME="ObjectIdentifierValueBlock";var Yt;class Pe extends A{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,zt),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}Yt=Pe;d.ObjectIdentifier=Yt;Pe.NAME="OBJECT IDENTIFIER";class Te extends M(K){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,r){if(r===0)return t;const s=B.toUint8Array(e);if(!R(this,s,t,r))return-1;const i=s.subarray(t,t+r);this.valueHexView=new Uint8Array(r);for(let a=0;a<r&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);const o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Q(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}const t=J(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",_;const r=new Uint8Array(t.byteLength);if(!e){const s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)r[o]=s[o]|128;r[i]=s[i]}return r.buffer}toString(){let e="";return this.isHexOnly?e=v.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}}Te.NAME="relativeSidBlock";class Qt extends x{constructor({value:e=ee,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let s=t;for(;r>0;){const i=new Te;if(s=i.fromBER(e,s,r),s===-1)return this.blockLength=0,this.error=i.error,s;this.blockLength+=i.blockLength,r-=i.blockLength,this.value.push(i)}return s}toBER(e,t){const r=[];for(let s=0;s<this.value.length;s++){const i=this.value[s].toBER(e);if(i.byteLength===0)return this.error=this.value[s].error,_;r.push(i)}return He(r)}fromString(e){this.value=[];let t=0,r=0,s="";do{r=e.indexOf(".",t),r===-1?s=e.substring(t):s=e.substring(t,r),t=r+1;const i=new Te;if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(r!==-1);return!0}toString(){let e="",t=!1;for(let r=0;r<this.value.length;r++){t=this.value[r].isHexOnly;let s=this.value[r].toString();r!==0&&(e=`${e}.`),t&&(s=`{${s}}`),e+=s}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}Qt.NAME="RelativeObjectIdentifierValueBlock";var er;class tr extends A{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Qt),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}er=tr;d.RelativeObjectIdentifier=er;tr.NAME="RelativeObjectIdentifier";var rr;class ye extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}rr=ye;d.Sequence=rr;ye.NAME="SEQUENCE";var sr;class nr extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}}sr=nr;d.Set=sr;nr.NAME="SET";class ir extends M(x){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=ee}toJSON(){return{...super.toJSON(),value:this.value}}}ir.NAME="StringValueBlock";class or extends ir{}or.NAME="SimpleStringValueBlock";class N extends Vt{constructor({...e}={}){super(e,or)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,B.toUint8Array(e))}fromString(e){const t=e.length,r=this.valueBlock.valueHexView=new Uint8Array(t);for(let s=0;s<t;s++)r[s]=e.charCodeAt(s);this.valueBlock.value=e}}N.NAME="SIMPLE STRING";class cr extends N{fromBuffer(e){this.valueBlock.valueHexView=B.toUint8Array(e);try{this.valueBlock.value=v.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=v.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(v.FromUtf8String(e)),this.valueBlock.value=e}}cr.NAME="Utf8StringValueBlock";var ar;class W extends cr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}ar=W;d.Utf8String=ar;W.NAME="UTF8String";class lr extends N{fromBuffer(e){this.valueBlock.value=v.ToUtf16String(e),this.valueBlock.valueHexView=B.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(v.FromUtf16String(e))}}lr.NAME="BmpStringValueBlock";var ur;class hr extends lr{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}ur=hr;d.BmpString=ur;hr.NAME="BMPString";class fr extends N{fromBuffer(e){const t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),r=new Uint8Array(t);for(let s=0;s<r.length;s+=4)r[s]=r[s+3],r[s+1]=r[s+2],r[s+2]=0,r[s+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){const t=e.length,r=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let s=0;s<t;s++){const i=J(e.charCodeAt(s),8),o=new Uint8Array(i);if(o.length>4)continue;const a=4-o.length;for(let c=o.length-1;c>=0;c--)r[s*4+c+a]=o[c]}this.valueBlock.value=e}}fr.NAME="UniversalStringValueBlock";var dr;class gr extends fr{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}dr=gr;d.UniversalString=dr;gr.NAME="UniversalString";var wr;class yr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}wr=yr;d.NumericString=wr;yr.NAME="NumericString";var Br;class br extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}Br=br;d.PrintableString=Br;br.NAME="PrintableString";var mr;class vr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}mr=vr;d.TeletexString=mr;vr.NAME="TeletexString";var kr;class Ar extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}kr=Ar;d.VideotexString=kr;Ar.NAME="VideotexString";var Sr;class xr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}Sr=xr;d.IA5String=Sr;xr.NAME="IA5String";var pr;class Er extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}pr=Er;d.GraphicString=pr;Er.NAME="GraphicString";var Nr;class Fe extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}Nr=Fe;d.VisibleString=Nr;Fe.NAME="VisibleString";var Ir;class Tr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}Ir=Tr;d.GeneralString=Ir;Tr.NAME="GeneralString";var Ur;class Vr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}Ur=Vr;d.CharacterString=Ur;Vr.NAME="CharacterString";var _r;class je extends Fe{constructor({value:e,valueDate:t,...r}={}){if(super(r),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let s=0;s<e.length;s++)this.valueBlock.valueHexView[s]=e.charCodeAt(s)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,B.toUint8Array(e)))}toBuffer(){const e=this.toString(),t=new ArrayBuffer(e.length),r=new Uint8Array(t);for(let s=0;s<e.length;s++)r[s]=e.charCodeAt(s);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){const r=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(r===null){this.error="Wrong input string for conversion";return}const s=parseInt(r[1],10);s>=50?this.year=1900+s:this.year=2e3+s,this.month=parseInt(r[2],10),this.day=parseInt(r[3],10),this.hour=parseInt(r[4],10),this.minute=parseInt(r[5],10),this.second=parseInt(r[6],10)}toString(e="iso"){if(e==="iso"){const t=new Array(7);return t[0]=p(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=p(this.month,2),t[2]=p(this.day,2),t[3]=p(this.hour,2),t[4]=p(this.minute,2),t[5]=p(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}}_r=je;d.UTCTime=_r;je.NAME="UTCTime";var Cr;class Hr extends je{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){const e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,r="",s="",i=0,o,a=0,c=0;if(e[e.length-1]==="Z")r=e.substring(0,e.length-1),t=!0;else{const h=new Number(e[e.length-1]);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");r=e}if(t){if(r.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(r.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let h=1,u=r.indexOf("+"),g="";if(u===-1&&(u=r.indexOf("-"),h=-1),u!==-1){if(g=r.substring(u+1),r=r.substring(0,u),g.length!==2&&g.length!==4)throw new Error("Wrong input string for conversion");let w=parseInt(g.substring(0,2),10);if(isNaN(w.valueOf()))throw new Error("Wrong input string for conversion");if(a=h*w,g.length===4){if(w=parseInt(g.substring(2,4),10),isNaN(w.valueOf()))throw new Error("Wrong input string for conversion");c=h*w}}}let l=r.indexOf(".");if(l===-1&&(l=r.indexOf(",")),l!==-1){const h=new Number(`0${r.substring(l)}`);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");i=h.valueOf(),s=r.substring(0,l)}else s=r;switch(!0){case s.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,l!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let h=60*i;this.minute=Math.floor(h),h=60*(h-this.minute),this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case s.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let h=60*i;this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case s.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){const h=1e3*i;this.millisecond=Math.floor(h)}break;default:throw new Error("Wrong input string for conversion")}const f=o.exec(s);if(f===null)throw new Error("Wrong input string for conversion");for(let h=1;h<f.length;h++)switch(h){case 1:this.year=parseInt(f[h],10);break;case 2:this.month=parseInt(f[h],10);break;case 3:this.day=parseInt(f[h],10);break;case 4:this.hour=parseInt(f[h],10)+a;break;case 5:this.minute=parseInt(f[h],10)+c;break;case 6:this.second=parseInt(f[h],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){const h=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=h.getUTCFullYear(),this.month=h.getUTCMonth(),this.day=h.getUTCDay(),this.hour=h.getUTCHours(),this.minute=h.getUTCMinutes(),this.second=h.getUTCSeconds(),this.millisecond=h.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){const t=[];return t.push(p(this.year,4)),t.push(p(this.month,2)),t.push(p(this.day,2)),t.push(p(this.hour,2)),t.push(p(this.minute,2)),t.push(p(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(p(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}}Cr=Hr;d.GeneralizedTime=Cr;Hr.NAME="GeneralizedTime";var Lr;class Rr extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}}Lr=Rr;d.DATE=Lr;Rr.NAME="DATE";var Mr;class Or extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}}Mr=Or;d.TimeOfDay=Mr;Or.NAME="TimeOfDay";var Dr;class $r extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}}Dr=$r;d.DateTime=Dr;$r.NAME="DateTime";var Pr;class Fr extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}}Pr=Fr;d.Duration=Pr;Fr.NAME="Duration";var jr;class qr extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}}jr=qr;d.TIME=jr;qr.NAME="TIME";function Cs(n){const e=n.slice().buffer,t=new ye({value:[new Pe({value:"1.3.101.110"})]}),r=new Oe({valueHex:e}),s=new ye({value:[t,r]});return new Uint8Array(s.toBER())}function Hs(n){const e=n.slice().buffer,s=Ts(e).result.valueBlock.value[1];return new Uint8Array(s.valueBlock.valueHex)}function ce(n){let e="";for(let t=0;t<n.length;t++)e+=String.fromCharCode(n[t]);return btoa(e)}function ae(n){const e=n.replace(/\s+/g,""),t=atob(e),r=new Uint8Array(t.length);for(let s=0;s<t.length;s++)r[s]=t.charCodeAt(s);return r}function ct(n){if(n instanceof ArrayBuffer)return n;const e=n,{buffer:t,byteOffset:r,byteLength:s}=e;if(t instanceof ArrayBuffer)return t.slice(r,r+s);const i=new Uint8Array(s);return i.set(new Uint8Array(t,r,s)),i.buffer}function ue(n){return n.buffer}async function Ls(n,e,t,r){const s=await crypto.subtle.importKey("raw",ue(n),"HKDF",!1,["deriveBits"]),i=await crypto.subtle.deriveBits({name:"HKDF",hash:"SHA-256",salt:ue(e),info:ue(t)},s,r*8);return new Uint8Array(i)}async function Rs(n){return crypto.subtle.importKey("raw",ue(n),{name:"HMAC",hash:"SHA-256"},!1,["sign"])}async function Ms(n,e){const t=await crypto.subtle.sign("HMAC",n,ue(e));return new Uint8Array(t)}function Os(n){const e=n.replace(/\r/g,"").match(/-----BEGIN [^-]+-----([\s\S]*?)-----END [^-]+-----/);if(!e)throw new Error("Invalid PEM");const t=e[1].replace(/[\n\r\s]/g,""),r=atob(t),s=new Uint8Array(r.length);for(let i=0;i<r.length;i++)s[i]=r.charCodeAt(i);return s.buffer}async function Ds(n,e,t){const r=Os(n),s=await crypto.subtle.importKey("spki",r,{name:"ECDSA",namedCurve:"P-256"},!0,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:"SHA-256"},s,ct(t),ct(e))}class Ue{constructor(e){this.ws=null,this.listeners={},this.subscriptions={request:{},status:{},topic:{}},this._shouldReconnect=!0,this._reconnectAttempt=0,this._reconnectTimeoutId=null,this.chunkBuffers={},this.generateRandomString=t=>{let r="";for(;r.length<t;)r+=Math.random().toString(36).substring(2,2+(t-r.length));return r},this.distributeMessage=t=>{const{correlation_id:r,status:s,topic:i}=t||{},o=this.subscriptions.request[r];o&&Object.values(o).forEach(l=>l(t));const a=this.subscriptions.status[s];a&&Object.values(a).forEach(l=>l(t));const c=this.subscriptions.topic[i];c&&Object.values(c).forEach(l=>l(t)),Object.values(this.listeners).forEach(l=>l(t))},this.client=e}async executeWithRetry(e,t=3){let r=0,s=1e3;for(;r<=t;)try{return await e()}catch(i){if(r++,r>t)throw i;console.warn(`[WPS] Claim check fetch failed. Retrying in ${s}ms...`),await new Promise(o=>setTimeout(o,s)),s*=2}throw new Error("Retry loop failed")}scheduleReconnect(){if(!this._shouldReconnect||this._reconnectTimeoutId)return;const e=Math.min(3e4,1e3*2**this._reconnectAttempt);this._reconnectAttempt++,console.log(`[WPS] Reconnecting in ${e}ms (Attempt ${this._reconnectAttempt})`),this._reconnectTimeoutId=setTimeout(async()=>{this._reconnectTimeoutId=null;try{await this.connect()}catch(t){console.warn("[WPS] Reconnection loop failed to fetch endpoint. Retrying...",t),this.scheduleReconnect()}},e)}close(){var e;this._shouldReconnect=!1,this._connectPromise=void 0,this._reconnectTimeoutId&&(clearTimeout(this._reconnectTimeoutId),this._reconnectTimeoutId=null),(e=this.ws)==null||e.close(),this.ws=null}async connect(){if(!this.client.getAccessToken())throw new Error("Cannot connect to notifications: user is not logged in.");if(!(this.ws&&(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)))return this._connectPromise?this._connectPromise:(this._connectPromise=new Promise(async(e,t)=>{let r=!1;try{const s=await this.client.get("/url/notifications"),{url:i}=s.data[0];if(!this._shouldReconnect){this._connectPromise=void 0,t(new Error("Connection aborted during token generation."));return}const o=new WebSocket(i);this.ws=o,o.onopen=()=>{this._reconnectAttempt=0,this._connectPromise=void 0,r=!0,e(),console.log("[WPS] Notification stream successfully connected.")},o.onmessage=async a=>{try{const c=JSON.parse(a.data);if(!c.ciphertext){const{operation_id:w,iv:m,signature:y,topic:C,correlation_id:X,content_type:re,...se}=c;if(!w)throw new Error("Claim check received but missing operation_id");const U=await this.executeWithRetry(()=>this.client.get(`/responses/${w}`,{},!0)),O={...se,content_type:re,topic:C,correlation_id:X,ciphertext:U.data,tot_pages:U.tot_pages,has_more:U.has_more,page_num:U.page_num,iv:m,signature:y},D=await this.client.decryptAndVerify(O);this.distributeMessage(D);return}const l=c.page_num,f=c.chunk_num,h=c.total_chunks;let u=c;if(h>1){this.chunkBuffers[l]||(this.chunkBuffers[l]={chunks:new Array(h),count:0,total:h});const w=this.chunkBuffers[l];if(w.chunks[f]===void 0&&(w.chunks[f]=c.ciphertext,w.count++),w.count<w.total)return;u={...c,ciphertext:w.chunks.join("")},delete this.chunkBuffers[l]}const g=await this.client.decryptAndVerify(u);this.distributeMessage(g)}catch(c){console.warn("Failed to process notification:",c)}},o.onerror=a=>{console.error("Notifications connection error",a)},o.onclose=()=>{console.log("Notifications socket disconnected"),r||(this._connectPromise=void 0,r=!0,t(new Error("WebSocket disconnected during handshake."))),this.ws===o&&(this.ws=null,this.scheduleReconnect())}}catch(s){this._connectPromise=void 0,r=!0,t(s)}}),this._connectPromise)}unsubscribe(e,t,r){delete this.subscriptions[e][t][r]}unlisten(e){delete this.listeners[e]}subscribe(e,t,r,s){let i=s??this.generateRandomString(16);return this.subscriptions[e]||(this.subscriptions[e]={}),this.subscriptions[e][t]||(this.subscriptions[e][t]={}),this.subscriptions[e][t][i]=r,()=>this.unsubscribe(e,t,i)}onMessage(e,t){let r=t??this.generateRandomString(16);return this.listeners[r]=e,()=>this.unlisten(r)}disconnect(){var e;(e=this.ws)==null||e.close(),this.ws=null}}const at="secure_api_session_v1";class Gr{constructor(e){this.session=null,this.pagingBuffer={},this.baseUrl=e.baseUrl,this.clientId=e.clientId,this.serverPublicKeyPem=e.serverPublicKeyPem,this.clientIdentityKeyPromise=Ps(e.clientIdentityPrivateKeyPem),this.loadPersistedSession(),this.notifications=new Ue(this),this.pagingBuffer={}}loadPersistedSession(){try{const e=localStorage.getItem(at);if(!e)return;const t=JSON.parse(e);if(!t)return;t.sessionId&&t.sessionExpiresAt?this.session={sessionId:t.sessionId,sessionExpiresAt:t.sessionExpiresAt,encKey:void 0,macKey:void 0,userId:t.userId,accessToken:t.accessToken,tokenType:t.tokenType,expiresAt:t.expiresAt,refreshToken:t.refreshToken}:this.session={sessionId:"",sessionExpiresAt:"",encKey:void 0,macKey:void 0,userId:t.userId,accessToken:t.accessToken,tokenType:t.tokenType,expiresAt:t.expiresAt,refreshToken:t.refreshToken}}catch{}}persistSession(){try{const e=this.session,t=e?{sessionId:e.sessionId,sessionExpiresAt:e.sessionExpiresAt,userId:e.userId,accessToken:e.accessToken,tokenType:e.tokenType,expiresAt:e.expiresAt,refreshToken:e.refreshToken}:{};localStorage.setItem(at,JSON.stringify(t))}catch{}}async handshake(){const e=await this.clientIdentityKeyPromise,t=xe.utils.randomSecretKey(),r=xe.getPublicKey(t),s=Cs(r),i=ce(s),o=await crypto.subtle.sign({name:"ECDSA",hash:"SHA-256"},e,Fs(s)),a=js(new Uint8Array(o)),c=ce(a),l=await fetch(`${this.baseUrl}/handshake`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:this.clientId,user_id:this.getUserId(),client_pub:i,client_sig:c,client_alg:"ES256"})});if(!l.ok)throw new Error(`Handshake failed: ${l.status} ${l.statusText}`);const f=await l.json(),{session_id:h,server_pub:u,server_sig:g,session_expires_at:w}=f;if(window.__akv={server_pub:u,server_sig:g},!h||!u||!g)throw new Error("Handshake response missing fields");const m=ae(u),y=ae(g);if(!await Ds(this.serverPublicKeyPem,m,y))throw new Error("Server signature verification failed");const X=Hs(m),re=xe.getSharedSecret(t,X),se=new Uint8Array(0),U=new TextEncoder().encode("health-api-v1"),O=await Ls(re,se,U,64),D=O.slice(0,32),be=O.slice(32,64),fe=await crypto.subtle.importKey("raw",D,"AES-GCM",!1,["encrypt","decrypt"]),ne=await Rs(be);this.updateSession({sessionId:h,encKey:fe,macKey:ne,sessionExpiresAt:w})}getUserId(){var e;return(e=this.session)==null?void 0:e.userId}getAccessToken(){var e;return(e=this.session)==null?void 0:e.accessToken}updateSession(e){if(!this.session){this.session=e,this.persistSession();return}Object.assign(this.session,e),this.persistSession()}getSession(){if(!this.session)throw new Error("No session");return this.session}async encryptBody(e){if(!e)return{ciphertextB64:"",ivB64:""};await this.ensureSession();const{encKey:t}=this.session,r=crypto.getRandomValues(new Uint8Array(12)),s=new TextEncoder().encode(JSON.stringify(e)),i=await crypto.subtle.encrypt({name:"AES-GCM",iv:r},t,s);return{ciphertextB64:ce(new Uint8Array(i)),ivB64:ce(r)}}async signRequest(e,t,r,s){await this.ensureSession();const{sessionId:i,macKey:o}=this.session,a=e.toUpperCase()==="GET"?"":{data:Array.isArray(r)?r:[r]},{ciphertextB64:c,ivB64:l}=await this.encryptBody(a),f=Math.floor(Date.now()/1e3).toString(),h=t.split("?")[0],u=`${e.toUpperCase()} ${h}
|
|
63
63
|
${f}
|
|
64
|
-
${c}`,g=await Ms(o,new TextEncoder().encode(u)),w=ce(g),m=new Headers({...s,"X-Session-Id":i,"X-Client-Id":this.clientId,"X-Timestamp":f,"X-Signature":w,"Content-Type":"application/json"});return this.getUserId()&&m.append("X-User-Id",this.getUserId()),this.getAccessToken()&&!this.isTokenExpired()&&m.append("Authorization",`Bearer ${this.getAccessToken()}`),{headers:m,payload:{content:c,iv:l}}}async get(e,t,r){const{headers:s}=await this.signRequest("GET",e,null,t),i=await fetch(`${this.baseUrl}${e}`,{method:"GET",headers:s});if(!i.ok)throw new Error(`GET ${e} failed: ${i.status} ${i.statusText}`);return r?await i.json():this.decryptAndVerify(await i.json())}async post(e,t,r){const{headers:s,payload:i}=await this.signRequest("POST",e,t,r),o=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:s,body:JSON.stringify(i)});if(!o.ok)throw new Error(`POST ${e} failed: ${o.status} ${o.statusText}`);return e.endsWith("/handshake")?await o.json():this.decryptAndVerify(await o.json())}async get_all_pages_async(e,t,r={}){const s=crypto.getRandomValues(new Uint8Array(10)),i=Array.from(s).join("-"),o=r?{...r,"X-Force-Sync":!1,"X-Request-Id":i}:{"X-Force-Sync":!1,"X-Request-Id":i};this.notifications.subscribe("request",i,async a=>{const{data:c,...l}=a;if(Object.keys(this.pagingBuffer).includes(i)||(this.pagingBuffer[i]={pages:new Array(l.tot_pages),count:0,total:l.tot_pages,data:[]}),this.pagingBuffer[i].pages[l.page_num-1]=l,this.pagingBuffer[i].data.push(...c),this.pagingBuffer[i].count++,l.tot_pages>l.page_num&&l.has_more&&this.pagingBuffer[i].count<this.pagingBuffer[i].total){let f=e.includes("?")?"&":"?";this.get(`${e}${f}page_num=${l.page_num+1}`,o);return}if(t)return t({tot_pages:l.tot_pages,page_num:l.tot_pages,has_more:!1,status:l.status,topic:l.topic,correlation_id:l.correlation_id,content_type:l.content_type,data:this.pagingBuffer[i].data})}),await this.get(e,o)}async get_all_pages_sync(e,t={}){const r=t?{...t,"X-Force-Sync":!0}:{"X-Force-Sync":!0};let s=await this.get(e,r);const i=[s];for(;s.tot_pages>s.page_num&&s.has_more;){let o=e.includes("?")?"&":"?";s=await this.get(`${e}${o}page_num=${s.page_num+1}`,{...t,"X-Force-Sync":!0}),i.push(s)}return i}async ensureSession(){var t,r,s;(!this.session||!this.session.sessionId||!this.session.sessionExpiresAt||!this.session.encKey||!this.session.macKey)&&await this.handshake();const e=new Date(Date.now()+5*60*1e3);(t=this.session)!=null&&t.sessionExpiresAt&&new Date((r=this.session)==null?void 0:r.sessionExpiresAt)<e&&await this.extendHandshake(),(s=this.session)!=null&&s.accessToken&&this.isTokenExpired()&&await this.refresh()}async extendHandshake(){await this.post("/handshake/extend",{}).then(async e=>{var t;e&&(e.session_id!==((t=this.session)==null?void 0:t.sessionId)?await this.handshake():this.updateSession({sessionExpiresAt:e.data[0].session_expires_at}))}).catch(async e=>{await this.handshake()})}async decryptAndVerify(e){const{ciphertext:t,iv:r,signature:s,...i}=e;if(!t||!r||!s)throw new Error("Malformed notification");const{encKey:o,macKey:a}=this.getSession(),c=ae(s),l=await crypto.subtle.sign("HMAC",a,new TextEncoder().encode(t));if(!this.constantTimeEqual(c,new Uint8Array(l)))throw new Error("Invalid notification signature");const f=Uint8Array.from(ae(r)),h=Uint8Array.from(ae(t)),u=await crypto.subtle.decrypt({name:"AES-GCM",iv:f},o,h),g=new TextDecoder().decode(u);return{...JSON.parse(g),...i}}constantTimeEqual(e,t){if(e.length!==t.length)return!1;let r=0;for(let s=0;s<e.length;s++)r|=e[s]^t[s];return r===0}async login(e){(!this.session||!this.session.sessionId||!this.session.sessionExpiresAt||!this.session.encKey||!this.session.macKey)&&await this.handshake(),this.updateSession({accessToken:void 0,tokenType:void 0,expiresAt:void 0,refreshToken:void 0});const t={};"username"in e&&"password"in e&&(t.username=e.username,t.password=e.password,t.scope=e.scope,t.oauth_session=e.oauthSession),"username"in e&&"otp"in e&&(t.username=e.username,t.otp=e.otp,t.scope=e.scope,t.oauth_session=e.oauthSession),"email"in e&&"socialLoginId"in e&&(t.email=e.email,t.social_login_id=e.socialLoginId,t.scope=e.scope,t.oauth_session=e.oauthSession),"jwt"in e&&this.updateSession({accessToken:e.jwt,tokenType:"Bearer"}),"refreshToken"in e&&(t.refresh_token=e.refreshToken);const r=await this.post("/oauth/authorize",t),{access_token:s,token_type:i,expires_at:o,refresh_token:a}=r.data[0];return s&&this.updateSession({accessToken:s}),i&&this.updateSession({tokenType:i}),o&&this.updateSession({expiresAt:o}),a&&this.updateSession({refreshToken:a}),{accessToken:s,tokenType:i,expiresAt:o,refreshToken:a}}async logout(){await this.post("/oauth/logout",{}),this.updateSession({accessToken:void 0,tokenType:void 0,expiresAt:void 0,refreshToken:void 0}),this.notifications=new Ue(this),await this.handshake()}async refresh(){const e=this.getSession();if(!(e!=null&&e.refreshToken))throw new Error("No refresh token available");if(e&&e.refreshToken)return this.login({refreshToken:e.refreshToken})}isTokenExpired(){const e=this.getSession();if(!(e!=null&&e.expiresAt))return!0;if(e&&e.expiresAt)return Math.floor(Date.now()/1e3)>=e.expiresAt}}function $s(n){const e=n.replace(/-----BEGIN PRIVATE KEY-----/,"").replace(/-----END PRIVATE KEY-----/,"").replace(/\s+/g,""),t=atob(e),r=new Uint8Array(t.length);for(let s=0;s<t.length;s++)r[s]=t.charCodeAt(s);return r.buffer}async function Ps(n){const e=$s(n);return crypto.subtle.importKey("pkcs8",e,{name:"ECDSA",namedCurve:"P-256"},!1,["sign"])}function Fs(n){return Uint8Array.from(n).buffer}function js(n){const e=n.slice(0,32),t=n.slice(32,64);function r(f){let h=0;for(;h<f.length-1&&f[h]===0;)h++;return f.slice(h)}function s(f){const h=r(f);if(h[0]&128){const u=new Uint8Array(h.length+1);return u[0]=0,u.set(h,1),u}return h}const i=s(e),o=s(t),a=2+i.length+2+o.length,c=new Uint8Array(2+a);let l=0;return c[l++]=48,c[l++]=a,c[l++]=2,c[l++]=i.length,c.set(i,l),l+=i.length,c[l++]=2,c[l++]=o.length,c.set(o,l),c}const Jr=Symbol("SDK_CLIENT"),qs={install(n,e){const t=new Gr(e);n.provide(Jr,t)}};exports.Notifications=Ue;exports.SDK_CLIENT=Jr;exports.SdkPlugin=qs;exports.SecureApiClient=Gr;
|
|
64
|
+
${c}`,g=await Ms(o,new TextEncoder().encode(u)),w=ce(g),m=new Headers({...s,"X-Session-Id":i,"X-Client-Id":this.clientId,"X-Timestamp":f,"X-Signature":w,"Content-Type":"application/json"});return this.getUserId()&&m.append("X-User-Id",this.getUserId()),this.getAccessToken()&&!this.isTokenExpired()&&m.append("Authorization",`Bearer ${this.getAccessToken()}`),{headers:m,payload:{content:c,iv:l}}}async get(e,t,r){const{headers:s}=await this.signRequest("GET",e,null,t),i=await fetch(`${this.baseUrl}${e}`,{method:"GET",headers:s});if(!i.ok)throw new Error(`GET ${e} failed: ${i.status} ${i.statusText}`);return r?await i.json():this.decryptAndVerify(await i.json())}async post(e,t,r){const{headers:s,payload:i}=await this.signRequest("POST",e,t,r),o=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:s,body:JSON.stringify(i)});if(!o.ok)throw new Error(`POST ${e} failed: ${o.status} ${o.statusText}`);return e.endsWith("/handshake")?await o.json():this.decryptAndVerify(await o.json())}async get_all_pages_async(e,t,r={}){const s=crypto.getRandomValues(new Uint8Array(10)),i=Array.from(s).join("-"),o=r?{...r,"X-Force-Sync":!1,"X-Request-Id":i}:{"X-Force-Sync":!1,"X-Request-Id":i};this.notifications.subscribe("request",i,async a=>{const{data:c,...l}=a;if(Object.keys(this.pagingBuffer).includes(i)||(this.pagingBuffer[i]={pages:new Array(l.tot_pages),count:0,total:l.tot_pages,data:[]}),this.pagingBuffer[i].pages[l.page_num-1]=l,this.pagingBuffer[i].data.push(...c),this.pagingBuffer[i].count++,l.tot_pages>l.page_num&&l.has_more&&this.pagingBuffer[i].count<this.pagingBuffer[i].total){let f=e.includes("?")?"&":"?";this.get(`${e}${f}page_num=${l.page_num+1}`,o);return}if(t)return t({tot_pages:l.tot_pages,page_num:l.tot_pages,has_more:!1,status:l.status,topic:l.topic,correlation_id:l.correlation_id,content_type:l.content_type,data:this.pagingBuffer[i].data})}),await this.get(e,o)}async get_all_pages_sync(e,t={}){const r=t?{...t,"X-Force-Sync":!0}:{"X-Force-Sync":!0};let s=await this.get(e,r);const i=[s];for(;s.tot_pages>s.page_num&&s.has_more;){let o=e.includes("?")?"&":"?";s=await this.get(`${e}${o}page_num=${s.page_num+1}`,{...t,"X-Force-Sync":!0}),i.push(s)}return i}async ensureSession(){var t,r,s;(!this.session||!this.session.sessionId||!this.session.sessionExpiresAt||!this.session.encKey||!this.session.macKey)&&await this.handshake();const e=new Date(Date.now()+5*60*1e3);(t=this.session)!=null&&t.sessionExpiresAt&&new Date((r=this.session)==null?void 0:r.sessionExpiresAt)<e&&await this.extendHandshake(),(s=this.session)!=null&&s.accessToken&&this.isTokenExpired()&&await this.refresh()}async extendHandshake(){await this.post("/handshake/extend",{}).then(async e=>{var t;e&&(e.session_id!==((t=this.session)==null?void 0:t.sessionId)?await this.handshake():this.updateSession({sessionExpiresAt:e.data[0].session_expires_at}))}).catch(async e=>{await this.handshake()})}async decryptAndVerify(e){const{ciphertext:t,iv:r,signature:s,...i}=e;if(!t||!r||!s)throw new Error("Malformed notification");const{encKey:o,macKey:a}=this.getSession(),c=ae(s),l=await crypto.subtle.sign("HMAC",a,new TextEncoder().encode(t));if(!this.constantTimeEqual(c,new Uint8Array(l)))throw new Error("Invalid notification signature");const f=Uint8Array.from(ae(r)),h=Uint8Array.from(ae(t)),u=await crypto.subtle.decrypt({name:"AES-GCM",iv:f},o,h),g=new TextDecoder().decode(u);return{...JSON.parse(g),...i}}constantTimeEqual(e,t){if(e.length!==t.length)return!1;let r=0;for(let s=0;s<e.length;s++)r|=e[s]^t[s];return r===0}async login(e){(!this.session||!this.session.sessionId||!this.session.sessionExpiresAt||!this.session.encKey||!this.session.macKey)&&await this.handshake(),this.updateSession({accessToken:void 0,tokenType:void 0,expiresAt:void 0,refreshToken:void 0});const t={};"username"in e&&"password"in e&&(t.username=e.username,t.password=e.password,t.scope=e.scope,t.oauth_session=e.oauthSession),"username"in e&&"otp"in e&&(t.username=e.username,t.otp=e.otp,t.scope=e.scope,t.oauth_session=e.oauthSession,t.oauth_flow_id=e.oauthFlowId),"email"in e&&"socialLoginId"in e&&(t.email=e.email,t.social_login_id=e.socialLoginId,t.scope=e.scope,t.oauth_session=e.oauthSession),"jwt"in e&&this.updateSession({accessToken:e.jwt,tokenType:"Bearer"}),"refreshToken"in e&&(t.refresh_token=e.refreshToken);const r=await this.post("/oauth/authorize",t),{access_token:s,token_type:i,expires_at:o,refresh_token:a}=r.data[0];return s&&this.updateSession({accessToken:s}),i&&this.updateSession({tokenType:i}),o&&this.updateSession({expiresAt:o}),a&&this.updateSession({refreshToken:a}),{accessToken:s,tokenType:i,expiresAt:o,refreshToken:a}}async logout(){await this.post("/oauth/logout",{}),this.updateSession({accessToken:void 0,tokenType:void 0,expiresAt:void 0,refreshToken:void 0}),this.notifications=new Ue(this),await this.handshake()}async refresh(){const e=this.getSession();if(!(e!=null&&e.refreshToken))throw new Error("No refresh token available");if(e&&e.refreshToken)return this.login({refreshToken:e.refreshToken})}isTokenExpired(){const e=this.getSession();if(!(e!=null&&e.expiresAt))return!0;if(e&&e.expiresAt)return Math.floor(Date.now()/1e3)>=e.expiresAt}}function $s(n){const e=n.replace(/-----BEGIN PRIVATE KEY-----/,"").replace(/-----END PRIVATE KEY-----/,"").replace(/\s+/g,""),t=atob(e),r=new Uint8Array(t.length);for(let s=0;s<t.length;s++)r[s]=t.charCodeAt(s);return r.buffer}async function Ps(n){const e=$s(n);return crypto.subtle.importKey("pkcs8",e,{name:"ECDSA",namedCurve:"P-256"},!1,["sign"])}function Fs(n){return Uint8Array.from(n).buffer}function js(n){const e=n.slice(0,32),t=n.slice(32,64);function r(f){let h=0;for(;h<f.length-1&&f[h]===0;)h++;return f.slice(h)}function s(f){const h=r(f);if(h[0]&128){const u=new Uint8Array(h.length+1);return u[0]=0,u.set(h,1),u}return h}const i=s(e),o=s(t),a=2+i.length+2+o.length,c=new Uint8Array(2+a);let l=0;return c[l++]=48,c[l++]=a,c[l++]=2,c[l++]=i.length,c.set(i,l),l+=i.length,c[l++]=2,c[l++]=o.length,c.set(o,l),c}const Jr=Symbol("SDK_CLIENT"),qs={install(n,e){const t=new Gr(e);n.provide(Jr,t)}};exports.Notifications=Ue;exports.SDK_CLIENT=Jr;exports.SdkPlugin=qs;exports.SecureApiClient=Gr;
|
|
65
65
|
//# sourceMappingURL=index.cjs.map
|