@factset/frontgate-js-sdk 7.0.10 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -240
- package/dist/lib/esnext/mixins/MessageCompressorMixin.js +1 -1
- package/dist/lib/esnext/mixins/auth/FetchAuthenticationWithOptionalCompressionMixin.js +165 -0
- package/dist/lib/esnext/mixins/auth/index.js +1 -0
- package/dist/lib/esnext/mixins/subscription/EndpointSubscriptionMixin.js +9 -0
- package/dist/lib/esnext/version.js +1 -1
- package/dist/lib/node/mixins/MessageCompressorMixin.js +1 -1
- package/dist/lib/node/mixins/auth/FetchAuthenticationWithOptionalCompressionMixin.js +169 -0
- package/dist/lib/node/mixins/auth/index.js +1 -0
- package/dist/lib/node/mixins/subscription/EndpointSubscriptionMixin.js +9 -0
- package/dist/lib/node/version.js +1 -1
- package/dist/lib/types/mixins/auth/FetchAuthenticationWithOptionalCompressionMixin.d.ts +54 -0
- package/dist/lib/types/mixins/auth/index.d.ts +1 -0
- package/dist/lib/types/mixins/index.d.ts +2 -2
- package/dist/lib/umd/mdg2.client.min.umd.js +1 -1
- package/dist/lib/umd/mdg2.client.umd.js +158 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(b,Re){typeof exports=="object"&&typeof module<"u"?Re(exports):typeof define=="function"&&define.amd?define(["exports"],Re):(b=typeof globalThis<"u"?globalThis:b||self,Re(b.fdsg={}))})(this,(function(b){"use strict";function Re(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var et,Pt;function _r(){if(Pt)return et;Pt=1;var r=function(p){return e(p)&&!t(p)};function e(l){return!!l&&typeof l=="object"}function t(l){var p=Object.prototype.toString.call(l);return p==="[object RegExp]"||p==="[object Date]"||o(l)}var n=typeof Symbol=="function"&&Symbol.for,s=n?Symbol.for("react.element"):60103;function o(l){return l.$$typeof===s}function i(l){return Array.isArray(l)?[]:{}}function c(l,p){return p.clone!==!1&&p.isMergeableObject(l)?T(i(l),l,p):l}function a(l,p,g){return l.concat(p).map(function(k){return c(k,g)})}function f(l,p){if(!p.customMerge)return T;var g=p.customMerge(l);return typeof g=="function"?g:T}function u(l){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(l).filter(function(p){return Object.propertyIsEnumerable.call(l,p)}):[]}function h(l){return Object.keys(l).concat(u(l))}function v(l,p){try{return p in l}catch{return!1}}function m(l,p){return v(l,p)&&!(Object.hasOwnProperty.call(l,p)&&Object.propertyIsEnumerable.call(l,p))}function M(l,p,g){var k={};return g.isMergeableObject(l)&&h(l).forEach(function(y){k[y]=c(l[y],g)}),h(p).forEach(function(y){m(l,y)||(v(l,y)&&g.isMergeableObject(p[y])?k[y]=f(y,g)(l[y],p[y],g):k[y]=c(p[y],g))}),k}function T(l,p,g){g=g||{},g.arrayMerge=g.arrayMerge||a,g.isMergeableObject=g.isMergeableObject||r,g.cloneUnlessOtherwiseSpecified=c;var k=Array.isArray(p),y=Array.isArray(l),I=k===y;return I?k?g.arrayMerge(l,p,g):M(l,p,g):c(p,g)}T.all=function(p,g){if(!Array.isArray(p))throw new Error("first argument should be an array");return p.reduce(function(k,y){return T(k,y,g)},{})};var _=T;return et=_,et}var Mr=_r();const xt=Re(Mr);function Er(r){return!!r&&typeof r=="object"}function Tr(...r){const e=r.filter(Er);return xt.all(e,{arrayMerge:(t,n)=>n})}function Ir(r){return r.replace(/[=]/g,"").replace(/\//g,"_").replace(/\+/g,"-")}class Ft{constructor(e){const t=Ir(e),n=Math.ceil(t.length/2);this.firstFactor=t.substring(0,n),this.secondFactor=t.substring(n)}getFirstFactor(){return this.firstFactor}getSecondFactor(){return this.secondFactor}}const he=-2,be=-2,$t=-1;function Rr(r){const e=[];if(r)for(let t=0;t<r.length;t++)e.push(r.readInt8(t));return e}var Ut=(r=>(r[r.DISCONNECTED=0]="DISCONNECTED",r[r.CONNECTING=1]="CONNECTING",r[r.AUTHENTICATED=2]="AUTHENTICATED",r[r.RECONNECTING=3]="RECONNECTING",r))(Ut||{}),Dt=(r=>(r[r.production=40]="production",r[r.preproduction=35]="preproduction",r[r.show=30]="show",r[r.testing=20]="testing",r))(Dt||{}),jt=(r=>(r.production="frontgate-eu.factsetdigitalsolutions.com",r.show="frontgate-eu.show.factsetdigitalsolutions.com",r))(jt||{}),Ht=(r=>(r.MAXIMUM_STRING="9223372036854775807",r.MINIMUM_STRING="-9223372036854775807",r))(Ht||{});function He(r){return r.toString().slice(0,-3)}const Gt={version:"7.0.10",package:"@factset/frontgate-js-sdk"};function Ar(){const r=Cr();return{userAgent:r.userAgent??"unknown",platform:"frontgate-js-sdk",version:Gt.version,package:Gt.package,mobile:/Mobi/i.test(r.userAgent??"unknown")}}function Cr(){return typeof navigator<"u"?navigator:typeof process<"u"?{userAgent:`node.js/io.js, ${process.version}`}:{userAgent:"unknown"}}const Or=r=>{const e=[18,20,9],t=n=>{for(let s=n.length;s>n.length-16;s-=2){let o=parseInt(n.substring(s-2,s),16);o>127&&(o-=256),e.push(o)}};return t(r.traceId),e.push(17),t(r.spanId),e.push(24),e.push(0),e},Nr=async(r,e)=>new Promise((t,n)=>{setTimeout(()=>{n(e)},r)}),Y=async(r,e,t)=>Promise.race([Nr(r,e),t]),qt=r=>r+Math.random()*100,Lt=6e3,X=class X{constructor(){this.headerMembers={dataset:{id_dataset:0},id_job:0,flags_r2:0,resend_counter:0,timeout:Lt,authentication_identifiers:{id_application:0,id_user:0},cache_key:{value:[]},previous_response_hash:{value:[]},tracing:{value:{value:[]}}},this.flags=[]}getPtlMessage(){return this.headerMembers}getQuality(){return Object.keys(X.PRICE_QUALITY).find(t=>X.PRICE_QUALITY[t]===this.headerMembers.dataset.id_dataset)}setQuality(e){this.headerMembers.dataset.id_dataset=X.PRICE_QUALITY[e]}setIdApplication(e,t=!1){(this.headerMembers.authentication_identifiers.id_application===0||t)&&(this.headerMembers.authentication_identifiers.id_application=e)}setIdUser(e,t=!1){(this.headerMembers.authentication_identifiers.id_user===0||t)&&(this.headerMembers.authentication_identifiers.id_user=e)}setFlag(e,t=!0){const n=this.flags.indexOf(e);t&&n===-1&&this.flags.push(e),!t&&n>-1&&this.flags.splice(n,1),this.headerMembers.flags_r2=this.getFlagsValue()}getFlagsValue(){return this.flags.reduce((e,t)=>e+X.FLAG_VALUE[t],0)}isFlagValueSet(e){return this.flags.find(t=>t===e)!==void 0}setJobId(e){this.headerMembers.id_job=e}getJobId(){return this.headerMembers.id_job}countResend(){this.headerMembers.resend_counter++}getResendCounter(){return this.headerMembers.resend_counter}setTimeout(e){if(e>0){this.headerMembers.timeout=e;return}throw new Error(`Attempted to set the timeout to "${e}". The timeout must be greater than 0.`)}getTimeout(){return this.headerMembers.timeout}setTracing(e){/^0+$/.test(e.traceId)||(this.headerMembers.tracing.value.value=Or(e))}static getDataSet(e){return Object.prototype.hasOwnProperty.call(X.PRICE_QUALITY,e)?X.PRICE_QUALITY[e]:X.PRICE_QUALITY.DLY}};X.PRICE_QUALITY={RLT:129,DLY:0,EOD:130},X.FLAG_VALUE={add_subscription:1,no_merge:2,support_caching:4,permission_denied_response:8,internal_client:16,current_state_refresh:32,subscription_use_pull_permissions:64,allow_chunked_response:128};let Ge=X;class me{constructor(e,t){this.header=new Ge,this.coreMembers={Message:e,Version:t},this.members={}}getPtlMessage(){const e={header:this.header.getPtlMessage()};return Tr(this.coreMembers,e,this.members)}}class qe{constructor(e,t){this.token=e,this.maximumIdleInterval=t}toJson(){const e=Ar();return{Message:"AuthenticationByTokenRequest",Version:1,token:{value:this.token},software:JSON.stringify(e),os:e.platform,feature_flags_wanted:{value:0},maximum_idle_interval:this.maximumIdleInterval,maximum_receivable_message_size:1048576,flags:0,cache_authentication_salt:{value:[]},cache_authentication_encrypted_secret:{encrypted_secret:[]}}}}const Z=class Z extends me{constructor(e,t,n,s,o=!1){super(Z.NAME,Z.VERSION),t&&this.header.setIdUser(t),n&&this.header.setIdApplication(n),s&&this.header.setTimeout(s),this.members.flags=o?Z.FLAG_SINGLE_USAGE:0,this.members.lifetime_seconds_r2=e??Z.LIFETIME_SECONDS_DEFAULT,this.header.setFlag("no_merge")}};Z.NAME="AuthenticationTokenRequest",Z.VERSION=6,Z.LIFETIME_SECONDS_DEFAULT=-1,Z.LIFETIME_SECONDS_MAXIMUM=-2,Z.FLAG_SINGLE_USAGE=1;let Le=Z;const ke=class ke extends me{constructor(e){super(ke.NAME,ke.VERSION),this.members.id_job_subscription=e}};ke.NAME="CancelSubscriptionRequest",ke.VERSION=6;let ye=ke;const ee=class ee extends me{constructor(e,t,n={},s){super(ee.NAME,ee.VERSION),this.members.accept="application/json",this.members.content_type="application/json",this.members.body={value:[]},this.members.query="",this.members.path=t,this.setMethod(e),Object.keys(n).length>0&&(e==="POST"?this.setBody(n):this.setQuery(n)),s&&this.setOptions(s)}setOptions(e){Object.hasOwnProperty.call(e,"accept")&&(this.members.accept=e.accept),Object.hasOwnProperty.call(e,"content_type")&&(this.members.content_type=e.content_type),Object.hasOwnProperty.call(e,"subscribe")&&e.subscribe&&this.header.setFlag("add_subscription"),Object.hasOwnProperty.call(e,"no_merge")&&e.no_merge&&this.header.setFlag("no_merge"),Object.hasOwnProperty.call(e,"allowChunkedResponse")&&e.allowChunkedResponse&&this.header.setFlag("allow_chunked_response"),Object.hasOwnProperty.call(e,"idApplication")&&e.idApplication&&this.header.setIdApplication(e.idApplication),Object.hasOwnProperty.call(e,"idUser")&&e.idUser&&this.header.setIdUser(e.idUser)}setMethod(e){const t=e==="POST"?ee.METHOD.POST:ee.METHOD.GET;this.members.method={value:t}}setBody(e={}){e instanceof Array?this.members.body={value:e}:this.members.body={value:JSON.stringify(e)}}getData(){return this.members.method.value===ee.METHOD.POST?ee.ptlToJsonData(this.members.body.value):this.members.query}setQuery(e={}){this.members.query=Object.keys(e).map(t=>`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`).join("&")}static ptlToJsonData(e){if(typeof e=="string")return JSON.parse(e);if(e instanceof Array&&e.length>0){let t="";return e.forEach(n=>{t+=String.fromCharCode(n)}),JSON.parse(t)}}};ee.NAME="HighLevelRequest",ee.VERSION=3,ee.METHOD={GET:1,POST:2};let we=ee;const V=class V extends me{constructor(e,t,n){super(V.NAME,V.VERSION),this.members.request={headers:{values:[{key:"accept",value:"application/json"},{key:"content-type",value:"application/json"}]},protocol:{value:V.PROTOCOL.HTTPS},host:"",port:0,path:t,query:"",body:{value:[]}},this.setQuery(),this.setMethod(e),n&&this.setOptions(n)}setOptions(e){e.no_merge&&this.header.setFlag("no_merge"),e.idApplication&&this.header.setIdApplication(e.idApplication),e.idUser&&this.header.setIdUser(e.idUser),e.protocol&&(this.members.request.protocol=e.protocol.toUpperCase()==="HTTP"?{value:V.PROTOCOL.HTTP}:{value:V.PROTOCOL.HTTPS}),e.method&&(this.members.request.method={value:V.METHOD[e.method]}),e.host&&(this.members.request.host=e.host),e.port&&(this.members.request.port=e.port),e.path&&(this.members.request.path=e.path),e.query&&(this.members.request.query=typeof e.query=="string"?e.query:Object.keys(e.query).map(t=>`${encodeURIComponent(t)}=${encodeURIComponent(e.query[t])}`).join("&")),e.body&&this.setBody(e.body),e.headers&&this.setHeaders(e.headers)}setHeaders(e){for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)){const n=e[t],s=this.members.request.headers.values.findIndex(i=>i.key===t);s!==-1&&this.members.request.headers.values.splice(s,1),this.members.request.headers.values.push({key:t,value:n})}}setQuery(){if(this.members.request.path.includes("?")){const e=this.members.request.path.split("?");this.members.request.path=e[0],this.members.request.query=e[1]}}setMethod(e){this.members.request.method={value:V.METHOD[e]}}setBody(e={}){return e instanceof Array||typeof e=="string"?this.members.request.body={value:e}:this.members.request.body={value:JSON.stringify(e)},this}getData(){if(this.members.request.body?.value)return we.ptlToJsonData(this.members.request.body.value)}};V.NAME="HTTPProxyRequest",V.VERSION=2,V.PROTOCOL={HTTP:1,HTTPS:2},V.METHOD={GET:1,POST:2,OPTIONS:3,HEAD:4,PUT:5,DELETE:6,TRACE:7,CONNECT:8};let Be=V;const _e=class _e{constructor(){this._timeAtSender=Date.now()}getPtlMessage(){return{Message:_e.NAME,Version:_e.VERSION,time_at_sender:{microseconds:this._timeAtSender*1e3}}}resetTimeAtSender(){this._timeAtSender=Date.now()}get timeAtSender(){return this._timeAtSender}};_e.NAME="PingRequest",_e.VERSION=3;let Ve=_e;class Bt extends me{constructor(e){super(e.Message,e.version?e.version:e.Version),this._extractRequestAttributes(e)}_extractRequestAttributes(e){for(const t of Object.keys(this.coreMembers))delete e[t];this.members=xt(this.members,e)}}class le{constructor(e){this.raw=e}get msg(){return this.raw}get name(){return this.raw.Message}get jobId(){return this.raw.header.id_job}get serviceId(){return this.raw.header.id_service}isUpdateMessage(){return Object.hasOwnProperty.call(this.raw,"header")?(Object.hasOwnProperty.call(this.raw.header,"id_service")||Object.hasOwnProperty.call(this.raw.header,"id_job"))&&this.raw.Message.endsWith("Update"):!1}isLossMessage(){return Object.hasOwnProperty.call(this.raw,"header")?(Object.hasOwnProperty.call(this.raw.header,"id_service")||Object.hasOwnProperty.call(this.raw.header,"id_job"))&&(this.raw.Message.endsWith("LossMessage")||this.raw.Message.endsWith("Loss")):!1}}class Vt extends le{constructor(e){if(super(e),!this.raw.token.value.b64)throw new Error("Token not set in AuthenticationTokenResponse");if(!this.raw.expiry.microseconds)throw new Error("Expiry not set in AuthenticationTokenResponse");this.token=this.raw.token.value.b64,this.expiry=parseInt(He(this.raw.expiry.microseconds),10)}getToken(){return this.token}getExpiry(){return this.expiry}}class z extends le{get reason(){return this.raw.details}get jobId(){return this.raw.id_job}}class Wt extends le{constructor(e){super(e);try{this.responseData=JSON.parse(this.raw.body.value)}catch(t){throw new Error(`Could not parse HighLevelResponse: ${t.message}`)}}get data(){return this.responseData.data}get meta(){return this.responseData.meta}get status(){return this.meta.status}get statusCode(){return this.status.code}}class Jt extends le{constructor(e){super(e);try{const t=this.raw.response.body.value,n=t.substr(0,1)==="{";this.responseData=n?JSON.parse(t):t}catch(t){throw new Error(`Could not parse HTTPProxyResponse: ${t}`)}this.responseInfo=this.raw.info,this.statusReason=this.raw.response.status_reason,this.statusCode=this.raw.response.status_code.value}get data(){return this.responseData}get meta(){return this.responseData.meta}get status(){return{code:this.statusCode,reason:this.statusReason}}}const Me=class Me{constructor(e){if(e.Message!==Me.NAME)throw new Error(`Unsupported message=${e.Message}`);if(e.Version!==Me.VERSION)throw new Error(`Unsupported version=${e.Version} for message=${e.Message}`);this._timeReceivedResponse=Date.now(),this._timeAtSender=Number(He(e.time_at_sender.microseconds)),this._timeFromRequest=Number(He(e.time_from_request.microseconds))}get timeAtPeer(){return this._timeAtSender}get timeOfRequest(){return this._timeFromRequest}get timeOfResponse(){return this._timeReceivedResponse}get latencyTotal(){return this._timeReceivedResponse-this._timeFromRequest}get latencyAtPeer(){return this._timeAtSender-this._timeFromRequest}};Me.NAME="Foundation::PingResponse",Me.VERSION=2;let We=Me;class tt extends le{constructor(e){if(super(e),typeof this.raw.body.value!="string")throw new Error("Incorrect response type in HighLevelUpdate");try{this.responseData=JSON.parse(this.raw.body.value)}catch(t){throw new Error(`Could not parse HighLevelUpdate: ${t.message}`)}}get data(){return this.responseData}}const rt=8;var d=(r=>(r[r.TRACE=10]="TRACE",r[r.DEBUG=20]="DEBUG",r[r.INFO=30]="INFO",r[r.WARN=40]="WARN",r[r.ERROR=50]="ERROR",r[r.FATAL=60]="FATAL",r[r.SILENT=100]="SILENT",r))(d||{});const ue=class ue{constructor(e=""){this.defaultLevel=40,this.noop=()=>null,this.name=e,this.setDefaultLevelFromLocalStorage(),Object.assign(ue.loggers,{[e]:this})}getName(){return this.name}setLevel(e){this.level=e}getLevel(){return typeof this.level=="number"&&isFinite(this.level)&&Math.floor(this.level)===this.level?this.level:this.defaultLevel}shouldLog(e){switch(this.getLevel()){case 100:return!1;case 60:return e==="fatal";case 50:return e==="fatal"||e==="error";case 40:return e==="fatal"||e==="error"||e==="warn";case 30:return e==="fatal"||e==="error"||e==="warn"||e==="info";case 20:return e==="fatal"||e==="error"||e==="warn"||e==="info"||e==="debug";default:return!0}}setDefaultLevelFromLocalStorage(){let e;try{if(!(typeof localStorage=="object"))return;const n=localStorage.getItem("loglevel");if(!n)return;e=n}catch{return}e&&this.setLevel(ue.getLogLevel(e))}static getLogLevel(e){const t=e.toLowerCase();switch(t){case"silent":return 100;case"fatal":return 60;case"error":return 50;case"warn":return 40;case"info":return 30;case"debug":return 20;case"trace":return 10;default:throw new Error(`Invalid log level: ${t}`)}}static getLogger(e,t){if(Object.prototype.hasOwnProperty.call(ue.loggers,e))return ue.loggers[e];const n=new t(e);return ue.loggers[e]=n,n}};ue.loggers={};let ie=ue;class Sr{static getLogLevel(e){const t=e.toLowerCase();switch(t){case"silent":return d.SILENT;case"fatal":return d.FATAL;case"error":return d.ERROR;case"warn":return d.WARN;case"info":return d.INFO;case"debug":return d.DEBUG;case"trace":return d.TRACE;default:throw new Error(`Invalid log level: ${t}`)}}}class nt extends ie{constructor(){super(...arguments),this.trace=this.getLogMethod("trace"),this.debug=this.getLogMethod("debug"),this.info=this.getLogMethod("info"),this.warn=this.getLogMethod("warn"),this.error=this.getLogMethod("error"),this.fatal=this.getLogMethod("fatal")}setLevel(e){this.level=e,this.trace=this.getLogMethod("trace"),this.debug=this.getLogMethod("debug"),this.info=this.getLogMethod("info"),this.warn=this.getLogMethod("warn"),this.error=this.getLogMethod("error"),this.fatal=this.getLogMethod("fatal")}getLogMethod(e){if(this.shouldLog(e)){const t=e==="debug"||e==="fatal"?"log":e,n=this.name?`${this.name}: [${e.toUpperCase()}] `:`-----> [${e.toUpperCase()}] `;return Function.prototype.bind.call(console[t],console,n)}return this.noop}static getLogger(e=""){return super.getLogger(e,nt)}}const Pr={silent:0,fatal:1,error:2,warn:3,info:4,debug:5,trace:6};class xr extends ie{constructor(e,t=""){super(t),this.name=t,this.logger=e,this.trace=Function.prototype.bind.call(e.trace,e),this.debug=Function.prototype.bind.call(e.debug,e),this.info=Function.prototype.bind.call(e.info,e),this.warn=Function.prototype.bind.call(e.warn,e),this.error=Function.prototype.bind.call(e.error,e),this.fatal=Function.prototype.bind.call(e.error,e)}setLevel(e){this.level=e,this.logger&&(this.logger.level=d[e].toLowerCase())}static getLogger(e=""){return Object.prototype.hasOwnProperty.call(ie.loggers,e)?ie.loggers[e]:null}}class st extends ie{constructor(){super(...arguments),this.trace=this.noop,this.debug=this.noop,this.info=this.noop,this.warn=this.noop,this.error=this.noop}static getLogger(e=""){return super.getLogger(e,st)}}const Fr=()=>j(e=>class extends e{async requestAuthenticationToken(t=30,n=0,s=0,o=this.defaultTimeoutInMs){const c={message:new Le(t,n,s,o).getPtlMessage(),callbackType:"job",callbackId:""};await this.hooks.callHook("frontgateConnection:sendMessage",c);const a=new Promise((u,h)=>{this.hooks.hookOnce(`frontgateConnection:response:${c.callbackId}`,v=>{if(!v.Message.includes("AuthenticationTokenResponse")){h(JSON.stringify(v));return}const m=new Vt(v);u({token:m.getToken(),expiry:m.getExpiry()})})}),f=`Request timeout reached (${o} ms) for ${c.message.Message}`;return Y(o,f,a)}async requestAuthenticationTokenForCookieTokenAuthentication(t=30,n=0,s=0,o=this.defaultTimeoutInMs){const i=await this.requestAuthenticationToken(t,n,s,o);return new Ft(i.token)}},{featureName:"AuthTokenRequest",featureGroups:["Misc"]}),$r=r=>j(t=>class extends t{async requestEndpoint(n,s,o,i,c=this.defaultTimeoutInMs){const a=new we(n,s,o,{...i,allowChunkedResponse:!r?.disableChunkedResponse});a.header.setTimeout(c),r?.allowPermissionDeniedResponse&&a.header.setFlag("permission_denied_response");const f={message:a.getPtlMessage(),callbackType:"job",callbackId:""};await this.hooks.callHook("frontgateConnection:sendMessage",f);const u=new Promise((v,m)=>{const M=[],T=()=>{this.hooks.hookOnce(`frontgateConnection:response:${f.callbackId}`,_=>{try{if(!_.Message.includes("HighLevelResponse")){m(JSON.stringify(_));return}if(this.#e(_))M.push({body:_.body?.value??"",processingTime:_.header?.processingTime??0}),T();else{M.push({body:_.body?.value??"",processingTime:_.header?.processingTime??0});const l=new Wt({..._,body:{value:M.map(p=>p.body).join("")},header:{..._.header,processingTime:M.reduce((p,g)=>p+g.processingTime,0)}});v({response:l,data:l.data})}}catch(l){m(l)}})};T()}),h=`Request timeout reached (${c} ms) for ${f.message.Message}`;return Y(c,h,u)}#e(n){return((n.header?.flags??0)&rt)===rt}},{featureName:"EndpointRequest",featureGroups:["Misc"]});var fe=null;typeof WebSocket<"u"?fe=WebSocket:typeof MozWebSocket<"u"?fe=MozWebSocket:typeof global<"u"?fe=global.WebSocket||global.MozWebSocket:typeof window<"u"?fe=window.WebSocket||window.MozWebSocket:typeof self<"u"&&(fe=self.WebSocket||self.MozWebSocket);const zt=r=>j(t=>class extends t{#e;#t;#r="disconnected";#n;#s=0;#i;#a;get#o(){return this.#e&&this.#e.readyState<2?this.#r:"disconnected"}#c;#u=[];set conf(n){const s=this.#b(n);this.#c=s.messageBufferSize,this.#t=s}constructor(...n){super(...n),this.#i=he,this.#a=$t,r&&(this.conf=r),this.hooks.hook("frontgateConnection:setIdApp",s=>{this.#i=s}),this.hooks.hook("frontgateConnection:setIdUser",s=>{this.#a=s}),this.hooks.hook("frontgateConnection:sendMessage",s=>{if(s.callbackType==="job"){const o=this.#p(s.message);s.callbackId=`${o}`,this.#f(s.message)}if(this.#o==="connected"&&s.callbackType==="response")this.#h(s.message);else if(this.#o==="authenticated")this.#h(s.message);else{if(this.#u.length>=this.#c)throw new Error("Message buffer is full");this.#u.push(s)}}),this.hooks.hook("frontgateConnection:authenticated",()=>{if(!this.#t)throw new Error("No connection configuration set");for(this.log(d.DEBUG,"Draining message buffer");this.#u.length>0;){const s=this.#u.shift();s&&(this.#f(s.message),this.#h(s.message))}this.#n=setInterval(()=>{this.log(d.DEBUG,"Sending keepalive"),this.hooks.callHook("frontgateConnection:sendMessage",{message:this.#g(),callbackType:"response",callbackId:"KeepAliveMessage"})},this.#t.maximumIdleIntervalInS/2*1e3)}),this.hooks.hook("reconnect:attempt",async()=>{clearInterval(this.#n),this.log(d.DEBUG,"Reconnecting"),await this.hooks.callHook("frontgateConnection:reset");try{await this.connect(),await this.hooks.callHook("reconnect:success")}catch(s){this.log(d.ERROR,"Reconnect failed",s),await this.hooks.callHook("reconnect:failed",s)}})}async connect(){if(!this.#t)throw new Error("No connection configuration set");if(this.#o!=="disconnected")throw new Error("Client is already connected or is connecting right now");const{host:n,port:s,tls:o,pathPrefix:i}=this.#t;this.#r="connecting";const a=`${o?"wss":"ws"}://${n}:${s}${i??""}/ws`,f={encoding:"jsjson-v2"};await this.hooks.callHook("frontgateConnection:afterSetEncoding",f);const[u,h]=f.encoding.split("-"),m=[`${h?`${h}.`:""}ws-${u}.mdgms.com`],M={url:a,subProtocols:m};try{await this.hooks.callHook("frontgateConnection:beforeConnect",M)}catch(l){throw this.#r="disconnected",l}this.log(d.DEBUG,`Connecting to ${M.url} with subprotocols ${M.subProtocols}`);const T=new Promise((l,p)=>{if(!this.#t)throw new Error("No connection configuration set");this.#t.wsClientOptions&&typeof window>"u"?this.#e=new fe(M.url,M.subProtocols,this.#t.wsClientOptions):this.#e=new fe(M.url,M.subProtocols),this.#e.binaryType="arraybuffer";let g;this.#e.onopen=()=>{this.#r="connected",this.log(d.DEBUG,"Connected"),this.hooks.callHook("frontgateConnection:connected",this.#t).catch(p),g=this.hooks.hookOnce("frontgateConnection:authenticated",()=>{this.#r="authenticated",this.log(d.DEBUG,"Authenticated"),l()})},this.#e.onclose=k=>{g?.(),this.log(d.DEBUG,"Disconnected",k),this.#r==="connecting"||this.#r==="connected"?p(JSON.stringify(k)):this.hooks.callHook("frontgateConnection:disconnected",k),clearInterval(this.#n),this.#r="disconnected"},this.#e.onerror=k=>{g?.(),this.log(d.ERROR,"Error:",k),this.hooks.callHook("frontgateConnection:error",k),(this.#r==="connecting"||this.#r==="connected")&&p(new Error("Websocket error")),clearInterval(this.#n),this.#r="disconnected"},this.#e.onmessage=k=>{const{data:y}=k;this.log(d.DEBUG,"Received data:",y);const I={msg:y};this.hooks.callHook("frontgateConnection:afterReceiveMessage",I).then(()=>{this.log(d.DEBUG,"Received message",I.msg);const O=I.msg.toString("utf-8"),E=JSON.parse(O);if(this.hooks.callHook("frontgateConnection:message",E),E.Message==="Foundation::DisconnectionMessage"){this.#e?.close(),this.hooks.callHook("frontgateConnection:disconnected",E);return}this.#l(E)})}}),_=`Timeout reached (${this.defaultTimeoutInMs} ms) for connection to ${a}`;return Y(this.defaultTimeoutInMs,_,T)}async disconnect(){return new Promise(n=>{this.#h(this.#d()),this.hooks.hookOnce("frontgateConnection:disconnected",()=>{this.#e?.close(),n()})})}#d(){return{Message:"Foundation::DisconnectionMessage",Version:3,reason:{value:64},details:"client shutdown"}}#g(){return{Message:"KeepAliveMessage",Version:2}}async#h(n){await this.hooks.callHook("frontgateConnection:beforeSerializeMessage",n);const s={msg:JSON.stringify(n)};await this.hooks.callHook("frontgateConnection:beforeSendMessage",s),this.log(d.DEBUG,"Sending message:",n),this.log(d.TRACE,"Sending data:",s.msg);try{this.#e?.send(s.msg)}catch(o){const i=this.#v(o,n);this.#l(i.msg)}}#l(n){if(typeof n.header?.id_job<"u"){this.hooks.callHook(`frontgateConnection:response:${n.header.id_job}`,n);return}if(typeof n.header?.id_service<"u"&&typeof n.id_notation<"u"){this.hooks.callHook(`frontgateConnection:response:${n.header.id_service}-${n.id_notation}`,n);return}if(typeof n.id_job<"u"){this.hooks.callHook(`frontgateConnection:response:${n.id_job}`,n);return}typeof n.Message=="string"&&this.hooks.callHook(`frontgateConnection:response:${n.Message.replace("Foundation::","")}`,n)}#p(n){this.#s+=1;const s=this.#s;return n.header={...n.header,id_job:s},this.#s}#f(n){n.header||(n.header={authentication_identifiers:{id_application:void 0,id_user:void 0}}),n.header.authentication_identifiers||(n.header={...n.header,authentication_identifiers:{id_application:void 0,id_user:void 0}}),n.header.authentication_identifiers.id_application||=this.#i,n.header.authentication_identifiers.id_user||=this.#a}#v(n,s){return new z({Message:"Foundation::ErrorResponse",Version:1,id_job:s.header?.id_job,reason:8,details:n})}#b(n){const s=n.maximumIdleIntervalInS??60,o=n.maximumIdleInterval??s*1e6;return{...n,payloadContent:n.payloadContent??"foundation",maximumIdleIntervalInS:s,maximumIdleInterval:o,tls:n.tls??!0,messageBufferSize:n.messageBufferSize??512}}isConnected(){return this.#o==="authenticated"}isDisconnected(){return this.#r!=="authenticated"}isReadyToConnect(){return this.#o==="disconnected"}},{featureName:"WSConnection",disabledFeatureGroups:["Connection"]}),Ur=(r,e)=>(e&&r.setLevel(e),j(n=>class extends n{constructor(...s){super(...s),this.logger=r}},{featureName:"Logger",featureGroups:["Misc"]}));var N=Uint8Array,L=Uint16Array,ot=Int32Array,Je=new N([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ze=new N([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),it=new N([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Kt=function(r,e){for(var t=new L(31),n=0;n<31;++n)t[n]=e+=1<<r[n-1];for(var s=new ot(t[30]),n=1;n<30;++n)for(var o=t[n];o<t[n+1];++o)s[o]=o-t[n]<<5|n;return{b:t,r:s}},Yt=Kt(Je,2),Qt=Yt.b,at=Yt.r;Qt[28]=258,at[258]=28;for(var Xt=Kt(ze,0),Dr=Xt.b,Zt=Xt.r,ct=new L(32768),C=0;C<32768;++C){var ae=(C&43690)>>1|(C&21845)<<1;ae=(ae&52428)>>2|(ae&13107)<<2,ae=(ae&61680)>>4|(ae&3855)<<4,ct[C]=((ae&65280)>>8|(ae&255)<<8)>>1}for(var te=(function(r,e,t){for(var n=r.length,s=0,o=new L(e);s<n;++s)r[s]&&++o[r[s]-1];var i=new L(e);for(s=1;s<e;++s)i[s]=i[s-1]+o[s-1]<<1;var c;if(t){c=new L(1<<e);var a=15-e;for(s=0;s<n;++s)if(r[s])for(var f=s<<4|r[s],u=e-r[s],h=i[r[s]-1]++<<u,v=h|(1<<u)-1;h<=v;++h)c[ct[h]>>a]=f}else for(c=new L(n),s=0;s<n;++s)r[s]&&(c[s]=ct[i[r[s]-1]++]>>15-r[s]);return c}),ce=new N(288),C=0;C<144;++C)ce[C]=8;for(var C=144;C<256;++C)ce[C]=9;for(var C=256;C<280;++C)ce[C]=7;for(var C=280;C<288;++C)ce[C]=8;for(var Ae=new N(32),C=0;C<32;++C)Ae[C]=5;var jr=te(ce,9,0),Hr=te(ce,9,1),Gr=te(Ae,5,0),qr=te(Ae,5,1),ut=function(r){for(var e=r[0],t=1;t<r.length;++t)r[t]>e&&(e=r[t]);return e},Q=function(r,e,t){var n=e/8|0;return(r[n]|r[n+1]<<8)>>(e&7)&t},ht=function(r,e){var t=e/8|0;return(r[t]|r[t+1]<<8|r[t+2]<<16)>>(e&7)},lt=function(r){return(r+7)/8|0},de=function(r,e,t){return(e==null||e<0)&&(e=0),(t==null||t>r.length)&&(t=r.length),new N(r.subarray(e,t))},Lr=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],U=function(r,e,t){var n=new Error(e||Lr[r]);if(n.code=r,Error.captureStackTrace&&Error.captureStackTrace(n,U),!t)throw n;return n},Br=function(r,e,t,n){var s=r.length,o=0;if(!s||e.f&&!e.l)return t||new N(0);var i=!t,c=i||e.i!=2,a=e.i;i&&(t=new N(s*3));var f=function(De){var je=t.length;if(De>je){var Ie=new N(Math.max(je*2,De));Ie.set(t),t=Ie}},u=e.f||0,h=e.p||0,v=e.b||0,m=e.l,M=e.d,T=e.m,_=e.n,l=s*8;do{if(!m){u=Q(r,h,1);var p=Q(r,h+1,3);if(h+=3,p)if(p==1)m=Hr,M=qr,T=9,_=5;else if(p==2){var I=Q(r,h,31)+257,O=Q(r,h+10,15)+4,E=I+Q(r,h+5,31)+1;h+=14;for(var w=new N(E),R=new N(19),A=0;A<O;++A)R[it[A]]=Q(r,h+A*3,7);h+=O*3;for(var P=ut(R),D=(1<<P)-1,S=te(R,P,1),A=0;A<E;){var H=S[Q(r,h,D)];h+=H&15;var g=H>>4;if(g<16)w[A++]=g;else{var $=0,x=0;for(g==16?(x=3+Q(r,h,3),h+=2,$=w[A-1]):g==17?(x=3+Q(r,h,7),h+=3):g==18&&(x=11+Q(r,h,127),h+=7);x--;)w[A++]=$}}var q=w.subarray(0,I),G=w.subarray(I);T=ut(q),_=ut(G),m=te(q,T,1),M=te(G,_,1)}else U(1);else{var g=lt(h)+4,k=r[g-4]|r[g-3]<<8,y=g+k;if(y>s){a&&U(0);break}c&&f(v+k),t.set(r.subarray(g,y),v),e.b=v+=k,e.p=h=y*8,e.f=u;continue}if(h>l){a&&U(0);break}}c&&f(v+131072);for(var Ue=(1<<T)-1,K=(1<<_)-1,oe=h;;oe=h){var $=m[ht(r,h)&Ue],W=$>>4;if(h+=$&15,h>l){a&&U(0);break}if($||U(2),W<256)t[v++]=W;else if(W==256){oe=h,m=null;break}else{var J=W-254;if(W>264){var A=W-257,F=Je[A];J=Q(r,h,(1<<F)-1)+Qt[A],h+=F}var ne=M[ht(r,h)&K],Ee=ne>>4;ne||U(3),h+=ne&15;var G=Dr[Ee];if(Ee>3){var F=ze[Ee];G+=ht(r,h)&(1<<F)-1,h+=F}if(h>l){a&&U(0);break}c&&f(v+131072);var Te=v+J;if(v<G){var Xe=o-G,Ze=Math.min(G,Te);for(Xe+v<0&&U(3);v<Ze;++v)t[v]=n[Xe+v]}for(;v<Te;++v)t[v]=t[v-G]}}e.l=m,e.p=oe,e.b=v,e.f=u,m&&(u=1,e.m=T,e.d=M,e.n=_)}while(!u);return v!=t.length&&i?de(t,0,v):t.subarray(0,v)},se=function(r,e,t){t<<=e&7;var n=e/8|0;r[n]|=t,r[n+1]|=t>>8},Ce=function(r,e,t){t<<=e&7;var n=e/8|0;r[n]|=t,r[n+1]|=t>>8,r[n+2]|=t>>16},ft=function(r,e){for(var t=[],n=0;n<r.length;++n)r[n]&&t.push({s:n,f:r[n]});var s=t.length,o=t.slice();if(!s)return{t:nr,l:0};if(s==1){var i=new N(t[0].s+1);return i[t[0].s]=1,{t:i,l:1}}t.sort(function(y,I){return y.f-I.f}),t.push({s:-1,f:25001});var c=t[0],a=t[1],f=0,u=1,h=2;for(t[0]={s:-1,f:c.f+a.f,l:c,r:a};u!=s-1;)c=t[t[f].f<t[h].f?f++:h++],a=t[f!=u&&t[f].f<t[h].f?f++:h++],t[u++]={s:-1,f:c.f+a.f,l:c,r:a};for(var v=o[0].s,n=1;n<s;++n)o[n].s>v&&(v=o[n].s);var m=new L(v+1),M=dt(t[u-1],m,0);if(M>e){var n=0,T=0,_=M-e,l=1<<_;for(o.sort(function(I,O){return m[O.s]-m[I.s]||I.f-O.f});n<s;++n){var p=o[n].s;if(m[p]>e)T+=l-(1<<M-m[p]),m[p]=e;else break}for(T>>=_;T>0;){var g=o[n].s;m[g]<e?T-=1<<e-m[g]++-1:++n}for(;n>=0&&T;--n){var k=o[n].s;m[k]==e&&(--m[k],++T)}M=e}return{t:new N(m),l:M}},dt=function(r,e,t){return r.s==-1?Math.max(dt(r.l,e,t+1),dt(r.r,e,t+1)):e[r.s]=t},er=function(r){for(var e=r.length;e&&!r[--e];);for(var t=new L(++e),n=0,s=r[0],o=1,i=function(a){t[n++]=a},c=1;c<=e;++c)if(r[c]==s&&c!=e)++o;else{if(!s&&o>2){for(;o>138;o-=138)i(32754);o>2&&(i(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(i(s),--o;o>6;o-=6)i(8304);o>2&&(i(o-3<<5|8208),o=0)}for(;o--;)i(s);o=1,s=r[c]}return{c:t.subarray(0,n),n:e}},Oe=function(r,e){for(var t=0,n=0;n<e.length;++n)t+=r[n]*e[n];return t},tr=function(r,e,t){var n=t.length,s=lt(e+2);r[s]=n&255,r[s+1]=n>>8,r[s+2]=r[s]^255,r[s+3]=r[s+1]^255;for(var o=0;o<n;++o)r[s+o+4]=t[o];return(s+4+n)*8},rr=function(r,e,t,n,s,o,i,c,a,f,u){se(e,u++,t),++s[256];for(var h=ft(s,15),v=h.t,m=h.l,M=ft(o,15),T=M.t,_=M.l,l=er(v),p=l.c,g=l.n,k=er(T),y=k.c,I=k.n,O=new L(19),E=0;E<p.length;++E)++O[p[E]&31];for(var E=0;E<y.length;++E)++O[y[E]&31];for(var w=ft(O,7),R=w.t,A=w.l,P=19;P>4&&!R[it[P-1]];--P);var D=f+5<<3,S=Oe(s,ce)+Oe(o,Ae)+i,H=Oe(s,v)+Oe(o,T)+i+14+3*P+Oe(O,R)+2*O[16]+3*O[17]+7*O[18];if(a>=0&&D<=S&&D<=H)return tr(e,u,r.subarray(a,a+f));var $,x,q,G;if(se(e,u,1+(H<S)),u+=2,H<S){$=te(v,m,0),x=v,q=te(T,_,0),G=T;var Ue=te(R,A,0);se(e,u,g-257),se(e,u+5,I-1),se(e,u+10,P-4),u+=14;for(var E=0;E<P;++E)se(e,u+3*E,R[it[E]]);u+=3*P;for(var K=[p,y],oe=0;oe<2;++oe)for(var W=K[oe],E=0;E<W.length;++E){var J=W[E]&31;se(e,u,Ue[J]),u+=R[J],J>15&&(se(e,u,W[E]>>5&127),u+=W[E]>>12)}}else $=jr,x=ce,q=Gr,G=Ae;for(var E=0;E<c;++E){var F=n[E];if(F>255){var J=F>>18&31;Ce(e,u,$[J+257]),u+=x[J+257],J>7&&(se(e,u,F>>23&31),u+=Je[J]);var ne=F&31;Ce(e,u,q[ne]),u+=G[ne],ne>3&&(Ce(e,u,F>>5&8191),u+=ze[ne])}else Ce(e,u,$[F]),u+=x[F]}return Ce(e,u,$[256]),u+x[256]},Vr=new ot([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),nr=new N(0),Wr=function(r,e,t,n,s,o){var i=o.z||r.length,c=new N(n+i+5*(1+Math.ceil(i/7e3))+s),a=c.subarray(n,c.length-s),f=o.l,u=(o.r||0)&7;if(e){u&&(a[0]=o.r>>3);for(var h=Vr[e-1],v=h>>13,m=h&8191,M=(1<<t)-1,T=o.p||new L(32768),_=o.h||new L(M+1),l=Math.ceil(t/3),p=2*l,g=function(St){return(r[St]^r[St+1]<<l^r[St+2]<<p)&M},k=new ot(25e3),y=new L(288),I=new L(32),O=0,E=0,w=o.i||0,R=0,A=o.w||0,P=0;w+2<i;++w){var D=g(w),S=w&32767,H=_[D];if(T[S]=H,_[D]=S,A<=w){var $=i-w;if((O>7e3||R>24576)&&($>423||!f)){u=rr(r,a,0,k,y,I,E,R,P,w-P,u),R=O=E=0,P=w;for(var x=0;x<286;++x)y[x]=0;for(var x=0;x<30;++x)I[x]=0}var q=2,G=0,Ue=m,K=S-H&32767;if($>2&&D==g(w-K))for(var oe=Math.min(v,$)-1,W=Math.min(32767,w),J=Math.min(258,$);K<=W&&--Ue&&S!=H;){if(r[w+q]==r[w+q-K]){for(var F=0;F<J&&r[w+F]==r[w+F-K];++F);if(F>q){if(q=F,G=K,F>oe)break;for(var ne=Math.min(K,F-2),Ee=0,x=0;x<ne;++x){var Te=w-K+x&32767,Xe=T[Te],Ze=Te-Xe&32767;Ze>Ee&&(Ee=Ze,H=Te)}}}S=H,H=T[S],K+=S-H&32767}if(G){k[R++]=268435456|at[q]<<18|Zt[G];var De=at[q]&31,je=Zt[G]&31;E+=Je[De]+ze[je],++y[257+De],++I[je],A=w+q,++O}else k[R++]=r[w],++y[r[w]]}}for(w=Math.max(w,A);w<i;++w)k[R++]=r[w],++y[r[w]];u=rr(r,a,f,k,y,I,E,R,P,w-P,u),f||(o.r=u&7|a[u/8|0]<<3,u-=7,o.h=_,o.p=T,o.i=w,o.w=A)}else{for(var w=o.w||0;w<i+f;w+=65535){var Ie=w+65535;Ie>=i&&(a[u/8|0]=f,Ie=i),u=tr(a,u+1,r.subarray(w,Ie))}o.i=i}return de(c,0,n+lt(u)+s)},sr=function(){var r=1,e=0;return{p:function(t){for(var n=r,s=e,o=t.length|0,i=0;i!=o;){for(var c=Math.min(i+2655,o);i<c;++i)s+=n+=t[i];n=(n&65535)+15*(n>>16),s=(s&65535)+15*(s>>16)}r=n,e=s},d:function(){return r%=65521,e%=65521,(r&255)<<24|(r&65280)<<8|(e&255)<<8|e>>8}}},or=function(r,e,t,n,s){if(!s&&(s={l:1},e.dictionary)){var o=e.dictionary.subarray(-32768),i=new N(o.length+r.length);i.set(o),i.set(r,o.length),r=i,s.w=o.length}return Wr(r,e.level==null?6:e.level,e.mem==null?s.l?Math.ceil(Math.max(8,Math.min(13,Math.log(r.length)))*1.5):20:12+e.mem,t,n,s)},ir=function(r,e,t){for(;t;++e)r[e]=t,t>>>=8},Jr=function(r,e){var t=e.level,n=t==0?0:t<6?1:t==9?3:2;if(r[0]=120,r[1]=n<<6|(e.dictionary&&32),r[1]|=31-(r[0]<<8|r[1])%31,e.dictionary){var s=sr();s.p(e.dictionary),ir(r,2,s.d())}},zr=function(r,e){return((r[0]&15)!=8||r[0]>>4>7||(r[0]<<8|r[1])%31)&&U(6,"invalid zlib data"),(r[1]>>5&1)==+!e&&U(6,"invalid zlib data: "+(r[1]&32?"need":"unexpected")+" dictionary"),(r[1]>>3&4)+2},gt=(function(){function r(e,t){if(typeof e=="function"&&(t=e,e={}),this.ondata=t,this.o=e||{},this.s={l:0,i:32768,w:32768,z:32768},this.b=new N(98304),this.o.dictionary){var n=this.o.dictionary.subarray(-32768);this.b.set(n,32768-n.length),this.s.i=32768-n.length}}return r.prototype.p=function(e,t){this.ondata(or(e,this.o,0,0,this.s),t)},r.prototype.push=function(e,t){this.ondata||U(5),this.s.l&&U(4);var n=e.length+this.s.z;if(n>this.b.length){if(n>2*this.b.length-32768){var s=new N(n&-32768);s.set(this.b.subarray(0,this.s.z)),this.b=s}var o=this.b.length-this.s.z;this.b.set(e.subarray(0,o),this.s.z),this.s.z=this.b.length,this.p(this.b,!1),this.b.set(this.b.subarray(-32768)),this.b.set(e.subarray(o),32768),this.s.z=e.length-o+32768,this.s.i=32766,this.s.w=32768}else this.b.set(e,this.s.z),this.s.z+=e.length;this.s.l=t&1,(this.s.z>this.s.w+8191||t)&&(this.p(this.b,t||!1),this.s.w=this.s.i,this.s.i-=2)},r.prototype.flush=function(){this.ondata||U(5),this.s.l&&U(4),this.p(this.b,!1),this.s.w=this.s.i,this.s.i-=2},r})(),pt=(function(){function r(e,t){typeof e=="function"&&(t=e,e={}),this.ondata=t;var n=e&&e.dictionary&&e.dictionary.subarray(-32768);this.s={i:0,b:n?n.length:0},this.o=new N(32768),this.p=new N(0),n&&this.o.set(n)}return r.prototype.e=function(e){if(this.ondata||U(5),this.d&&U(4),!this.p.length)this.p=e;else if(e.length){var t=new N(this.p.length+e.length);t.set(this.p),t.set(e,this.p.length),this.p=t}},r.prototype.c=function(e){this.s.i=+(this.d=e||!1);var t=this.s.b,n=Br(this.p,this.s,this.o);this.ondata(de(n,t,this.s.b),this.d),this.o=de(n,this.s.b-32768),this.s.b=this.o.length,this.p=de(this.p,this.s.p/8|0),this.s.p&=7},r.prototype.push=function(e,t){this.e(e),this.c(t)},r})(),Kr=(function(){function r(e,t){this.c=sr(),this.v=1,gt.call(this,e,t)}return r.prototype.push=function(e,t){this.c.p(e),gt.prototype.push.call(this,e,t)},r.prototype.p=function(e,t){var n=or(e,this.o,this.v&&(this.o.dictionary?6:2),t&&4,this.s);this.v&&(Jr(n,this.o),this.v=0),t&&ir(n,n.length-4,this.c.d()),this.ondata(n,t)},r.prototype.flush=function(){gt.prototype.flush.call(this)},r})(),Yr=(function(){function r(e,t){pt.call(this,e,t),this.v=e&&e.dictionary?2:1}return r.prototype.push=function(e,t){if(pt.prototype.e.call(this,e),this.v){if(this.p.length<6&&!t)return;this.p=this.p.subarray(zr(this.p,this.v-1)),this.v=0}t&&(this.p.length<4&&U(6,"invalid zlib data"),this.p=this.p.subarray(0,-4)),pt.prototype.c.call(this,t)},r})(),ar=typeof TextEncoder<"u"&&new TextEncoder,vt=typeof TextDecoder<"u"&&new TextDecoder,Qr=0;try{vt.decode(nr,{stream:!0}),Qr=1}catch{}var Xr=function(r){for(var e="",t=0;;){var n=r[t++],s=(n>127)+(n>223)+(n>239);if(t+s>r.length)return{s:e,r:de(r,t-1)};s?s==3?(n=((n&15)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,e+=String.fromCharCode(55296|n>>10,56320|n&1023)):s&1?e+=String.fromCharCode((n&31)<<6|r[t++]&63):e+=String.fromCharCode((n&15)<<12|(r[t++]&63)<<6|r[t++]&63):e+=String.fromCharCode(n)}};function Zr(r,e){var t;if(ar)return ar.encode(r);for(var n=r.length,s=new N(r.length+(r.length>>1)),o=0,i=function(f){s[o++]=f},t=0;t<n;++t){if(o+5>s.length){var c=new N(o+8+(n-t<<1));c.set(s),s=c}var a=r.charCodeAt(t);a<128||e?i(a):a<2048?(i(192|a>>6),i(128|a&63)):a>55295&&a<57344?(a=65536+(a&1047552)|r.charCodeAt(++t)&1023,i(240|a>>18),i(128|a>>12&63),i(128|a>>6&63),i(128|a&63)):(i(224|a>>12),i(128|a>>6&63),i(128|a&63))}return de(s,0,o)}function en(r,e){var t;if(vt)return vt.decode(r);var n=Xr(r),s=n.s,t=n.r;return t.length&&U(8),s}const tn=r=>{if(r.length===1)return r[0];const e=new Uint8Array(r.reduce((t,n)=>t+n.length,0));for(let t=0,n=0;t<r.length;++t)e.set(r[t],n),n+=r[t].length;return e};class rn{constructor(){this.reset()}reset(){this.compressor=null,this.decompressor=null}compress(e){this.compressor||(this.compressor=new Kr({mem:4}));const t=[];return this.compressor.ondata=n=>{t.push(n)},this.compressor.push(Zr(e)),this.compressor.flush(),tn(t)}decompress(e){this.decompressor||(this.decompressor=new Yr);let t;this.decompressor.ondata=n=>{t=n};try{if(this.decompressor.push(e),t===void 0)throw new Error("invalid block type")}catch(n){throw new Error(`Decompression error: ${n.message}, length: ${e.length}, data: [${e.toString()}]`)}return en(t)}}const nn=()=>j(e=>class extends e{#e;constructor(...t){super(...t),this.#e=new rn,this.hooks.hook("frontgateConnection:reset",()=>{this.#e.reset()}),this.hooks.hook("frontgateConnection:afterSetEncoding",n=>{n.encoding="jsjsonc-v2"}),this.hooks.hook("frontgateConnection:beforeSendMessage",n=>{const s=this.#e.compress(n.msg);n.msg=s}),this.hooks.hook("frontgateConnection:afterReceiveMessage",n=>{const s=this.#e.decompress(new Uint8Array(n.msg));n.msg=s})}},{featureName:"MessageCompressor",featureGroups:["Misc"]}),sn=()=>j(e=>class extends e{async request(t,n=this.defaultTimeoutInMs){t.header.setTimeout(n);const s={message:t.getPtlMessage(),callbackType:"job",callbackId:""};await this.hooks.callHook("frontgateConnection:sendMessage",s);const o=new Promise(c=>{this.hooks.hookOnce(`frontgateConnection:response:${s.callbackId}`,a=>{const f=new le(a);c(f)})}),i=`Request timeout reached (${n} ms) for ${s.message.Message}`;return Y(n,i,o)}},{featureName:"Request",featureGroups:["Misc"]}),on=r=>j(t=>{const n={...r};return class extends t{#e=new Map;#t=new Map;#r=new Map;async observeEndpoint(s,o,i,c){const a=`${s}:${o}:${JSON.stringify(i)}:${JSON.stringify(c??{})}`;if(this.#r.has(a)){const l=this.#r.get(a);this.log(d.INFO,`Catching inflight subscription for ${a}`);const p=this.#t.get(a)??0;return this.#t.set(a,p+1),l}const f=n.timeout??this.defaultTimeoutInMs,u=n.subscriptionResubscribeTimeout??1e3;if(this.#e.has(a)){const l=this.#e.get(a),p=this.#t.get(a)??0;if(l)return this.#t.set(a,p+1),this.log(d.INFO,`Reusing existing subscription for ${a}`),l}this.log(d.INFO,`Creating new subscription for ${a}`);const h=new we(s,o,i,{...c,subscribe:!0});h.header.setTimeout(f);const v={message:h.getPtlMessage(),callbackType:"job",callbackId:""};let m=!1;const M=new Promise((l,p)=>{this.hooks.callHook("frontgateConnection:sendMessage",v).then(()=>{this.hooks.hookOnce(`frontgateConnection:response:${v.callbackId}`,g=>{if(!g.Message.includes("HighLevelResponse")){this.log(d.ERROR,`Unexpected response: ${g.Message}`),p(new z(JSON.stringify(g)));return}let k;try{k=JSON.parse(g.body.value)}catch(R){this.log(d.ERROR,`Failed to parse response: ${g.body.value}`),this.log(d.ERROR,R),p(R);return}const y=new cr(g.header.id_job,k);let I=this.hooks.hook(`frontgateConnection:response:${v.callbackId}`,R=>{if(!R.Message.includes("HighLevelUpdate")){if(R.Message.includes("SubscriptionLoss")){this.log(d.DEBUG,`Received: ${R.Message}`),setTimeout(()=>{O()},qt(u)),I();return}this.log(d.ERROR,`Unexpected response: ${g.Message}`),y.pushError(new z(JSON.stringify(R))),I();return}let A;try{A=new tt(R)}catch(P){this.log(d.ERROR,`Failed to parse response: ${R.body.value}`),y.pushError(P);return}y.pushPatchData(A.data)});const O=async()=>{I(),this.log(d.INFO,`Resubscribing to ${a} due to reconnect`),await this.hooks.callHook("frontgateConnection:sendMessage",v);const R=new Promise((A,P)=>{this.hooks.hookOnce(`frontgateConnection:response:${v.callbackId}`,D=>{if(!D.Message.includes("HighLevelResponse")){const S=new z(D);this.log(d.ERROR,`Unexpected response: ${D.Message}`),I(),P(S);return}if(this.log(d.INFO,`Resubscribed to ${a} with ${D.header.id_job}`),y.idJob=D.header.id_job,m){this.log(d.WARN,`Zombie subscription detected for ${a}. Initiating unsubscribe.`),y.unsubscribe(),A();return}I=this.hooks.hook(`frontgateConnection:response:${D.header.id_job}`,S=>{if(!S.Message.includes("HighLevelUpdate")){if(S.Message.includes("SubscriptionLoss")){this.log(d.DEBUG,`Received: ${S.Message}`),setTimeout(()=>{O()},qt(u));return}this.log(d.ERROR,`Unexpected response: ${S.Message}`);const $=new z(S);y.pushError($);return}let H;try{H=new tt(S)}catch($){this.log(d.ERROR,`Failed to parse response: ${S.body.value}`),y.pushError($);return}y.pushPatchData(H.data)}),A()})});try{await Y(f,"Request timeout reached",R)}catch(A){m=!0,y.pushError(new z({Message:"Resubscribe failed",Error:A}))}},E=this.hooks.hook("reconnect:success",O);y.unsubscribe=()=>{if(this.#e.get(a)){const D=this.#t.get(a)??0;if(this.#t.set(a,D-1),D-1>0){this.log(d.INFO,`Not unsubscribing from ${a} as there are still ${D} subscribers`);return}this.#e.delete(a),this.#t.delete(a),m=!0}this.log(d.INFO,`Unsubscribing from ${a}`);const P={message:new ye(y.idJob).getPtlMessage(),callbackType:"job",callbackId:""};this.hooks.callHook("frontgateConnection:sendMessage",P),I(),E()},this.#e.set(a,y);const w=this.#t.get(a)??0;if(this.#t.set(a,w+1),m){this.log(d.WARN,`Zombie subscription detected for ${a}. Initiating unsubscribe.`),y.unsubscribe();return}l(y)})}).catch(g=>{p(g)})}),T=`Request timeout reached (${f} ms) for ${v.message.Message}`,_=Y(f,T,M).catch(l=>{throw m=!0,this.#t.delete(a),this.#e.delete(a),l}).finally(()=>{this.#r.delete(a)});return this.#r.set(a,_),_}}},{featureName:"EndpointSubscriptions",featureGroups:["Misc"]}),an=()=>j(e=>class extends e{#e=new Map;async observe(t,n=this.defaultTimeoutInMs){return this.#t(t,"job",void 0,n)}async observeConnectionBased(t,n,s=this.defaultTimeoutInMs){return this.#t(t,"connection",n,s)}async#t(t,n,s,o=this.defaultTimeoutInMs){const i=JSON.stringify(t.getPtlMessage());if(this.#e.has(i)){const h=this.#e.get(i);if(h)return h.count++,this.log(d.INFO,`Reusing existing subscription for ${i}`),h.observer}this.log(d.INFO,`Creating new subscription for ${i}`);const a={message:t.getPtlMessage(),callbackType:"job",callbackId:""};await this.hooks.callHook("frontgateConnection:sendMessage",a);const f=new Promise((h,v)=>{this.hooks.hookOnce(`frontgateConnection:response:${a.callbackId}`,m=>{if(m.Message.includes("Error")||m.Message.includes("PermissionDenied")){this.log(d.ERROR,`Unexpected response: ${m.Message}`),v(new Error(`Unexpected response: ${m.Message}`));return}const M=n==="connection"?`${m.header.id_service}-${t.getPtlMessage().id_notation}`:m.header.id_job,T=typeof s>"u"?new ye(m.header.id_job):new s(m.header.id_service,t.getPtlMessage().id_notation),_=new mt(m.header.id_job,m);let l=this.hooks.hook(`frontgateConnection:response:${M}`,g=>{if(g.Message.includes("Error")||g.Message.includes("PermissionDenied")){this.log(d.ERROR,`Unexpected response: ${m.Message}`),_.pushError(new z(JSON.stringify(g)));return}_.pushData(g)});const p=this.hooks.hook("reconnect:success",async()=>{l(),this.log(d.INFO,`Resubscribing to ${i} due to reconnect`),await this.hooks.callHook("frontgateConnection:sendMessage",a);const g=new Promise((k,y)=>{this.hooks.hookOnce(`frontgateConnection:response:${a.callbackId}`,I=>{if(I.Message.includes("Error")||I.Message.includes("PermissionDenied")){const w=new z(I);this.log(d.ERROR,`Unexpected resp: ${I.Message}`),y(w);return}const O=n==="connection"?`${I.header.id_service}-${t.getPtlMessage().id_notation}`:I.header.id_job,E=typeof s>"u"?new ye(I.header.id_job):new s(I.header.id_service,t.getPtlMessage().id_notation);_.idJob=I.header.id_job,l=this.hooks.hook(`frontgateConnection:response:${O}`,w=>{if(w.Message.includes("Error")||w.Message.includes("PermissionDenied")){this.log(d.ERROR,`Unexpected response: ${w.Message}`);const R=new z(w);_.pushError(R);return}_.unsubscribe=()=>{const R=this.#e.get(i);if(R){if(R.count--,R.count>0){this.log(d.INFO,`Not unsubscribing from ${i} as there are still ${R.count} subscribers`);return}this.#e.delete(i)}this.log(d.INFO,`Unsubscribing from ${i}`);const A={message:E.getPtlMessage(),callbackType:"job",callbackId:""};this.hooks.callHook("frontgateConnection:sendMessage",A),l(),p()},_.pushData(w)}),k()})});try{await Y(o,"Request timeout reached",g)}catch(k){_.pushError(new z({Message:"Reconnect failed",Error:k}))}});_.unsubscribe=()=>{const g=this.#e.get(i);if(g){if(g.count--,g.count>0){this.log(d.INFO,`Not unsubscribing from ${i} as there are still ${g.count} subscribers`);return}this.#e.delete(i)}this.log(d.INFO,`Unsubscribing from ${i}`);const k={message:T.getPtlMessage(),callbackType:"job",callbackId:""};this.hooks.callHook("frontgateConnection:sendMessage",k),l(),p()},this.#e.set(i,{observer:_,count:1}),h(_)})}),u=`Request timeout reached (${o} ms) for ${a.message.Message}`;return Y(o,u,f)}},{featureName:"RawSubscriptions",featureGroups:["Misc"]}),bt=(r,e)=>{const t=e.split("/").slice(1);let n=r;for(let s=0;s<t.length-1;s++){const o=decodeURIComponent(t[s]);if(!(o in n))throw new Error(`Path not found: ${e}`);n=n[o]}return[n,decodeURIComponent(t[t.length-1])]},cn=(r,e,t)=>{const[n,s]=bt(r,e);n[s]=t},un="-",hn=(r,e,t)=>{const[n,s]=bt(r,e);Array.isArray(n)?s===un?n.push(t):n.splice(parseInt(s,10),0,t):n[s]=t},ln=(r,e)=>{const[t,n]=bt(r,e);Array.isArray(t)?t.splice(parseInt(n,10),1):delete t[n]};function fn(r,e){return e.forEach(t=>{switch(t.op){case"replace":cn(r,t.path,t.value);break;case"add":hn(r,t.path,t.value);break;case"remove":ln(r,t.path);break;default:throw new Error(`Unsupported op: ${t.op}`)}}),r}class mt{#e;#t=[];#r=[];get data(){return this.#e}constructor(e,t){this.#e=t,this.idJob=e}subscribe({next:e,error:t}){e(this.#e),t&&this.#r.push(t),this.#t.push(e)}pushData(e){this.#e=e,this.#t.forEach(t=>{t(e)})}pushError(e){this.#r.forEach(t=>{t(e)})}}class cr extends mt{pushPatchData(e){try{const t=fn(this.data,e);super.pushData(t)}catch(t){super.pushError(new z(t.message))}}}const dn=r=>j(t=>class extends t{constructor(...n){super(...n),this.hooks.hook("frontgateConnection:beforeConnect",o=>{this.hooks.callHook("frontgateConnection:setIdApp",he),this.hooks.callHook("frontgateConnection:setIdUser",be),this.log(d.DEBUG,"Adding mdg2auth subprotocol"),o.subProtocols.push(`mdg2auth-${r}`)});const s=async o=>{this.hooks.callHook("frontgateConnection:setIdApp",he),this.hooks.callHook("frontgateConnection:setIdUser",be);const i={maximum_idle_interval:o.maximumIdleInterval},c={b64:""},f=new qe(c,i.maximum_idle_interval).toJson();this.log(d.INFO,"Sending message",f);const u={message:f,callbackType:"response",callbackId:f.Message.replace("Request","Response")};await this.hooks.callHook("frontgateConnection:sendMessage",u),this.hooks.hookOnce(`frontgateConnection:response:${u.callbackId}`,h=>{this.log(d.INFO,"Received response",h),this.hooks.callHook("frontgateConnection:authenticated")})};this.hooks.hookOnce("frontgateConnection:connected",s)}},{featureName:"CookieTokenAuth",featureGroups:["Auth"],disabledFeatureGroups:["Auth"]}),gn=r=>j(t=>class extends t{#e;constructor(...n){super(...n),this.#e=r??"";const s=async o=>{this.hooks.callHook("frontgateConnection:setIdApp",he),this.hooks.callHook("frontgateConnection:setIdUser",be);const i={maximum_idle_interval:o.maximumIdleInterval},c={b64:this.#e},f=new qe(c,i.maximum_idle_interval).toJson();this.log(d.INFO,"Sending message",f);const u={message:f,callbackType:"response",callbackId:f.Message.replace("Request","Response")};await this.hooks.callHook("frontgateConnection:sendMessage",u),this.hooks.hookOnce(`frontgateConnection:response:${u.callbackId}`,h=>{this.log(d.INFO,"Received response",h),this.hooks.callHook("frontgateConnection:authenticated")})};this.hooks.hook("frontgateConnection:connected",s)}set token(n){this.#e=n}},{featureName:"TokenAuth",featureGroups:["Auth"],disabledFeatureGroups:["Auth"]}),pn=(r,e,t)=>j(s=>class extends zt({host:"",pathPrefix:"",port:0,tls:!0,maximumIdleIntervalInS:r.maximumIdleIntervalInS})(s){#e="";#t="";#r;#n;constructor(...o){super(...o),this.#r=e,this.#n=t,this.hooks.hook("frontgateConnection:beforeConnect",async c=>{this.hooks.callHook("frontgateConnection:setIdApp",he),this.hooks.callHook("frontgateConnection:setIdUser",be),this.log(d.DEBUG,"Fetching connection configuration");const a=await this.#s();if(this.log(d.DEBUG,"Connection configuration received",a),c.url=a.url,a.authtenticationType==="token"&&a.authenticationToken)this.#e=a.authenticationToken;else if(a.splitAuthenticationTokenSecondFactor)this.#t=a.splitAuthenticationTokenSecondFactor;else throw new Error("Invalid authentication configuration");this.log(d.DEBUG,"Adding mdg2auth subprotocol"),this.#t!==""&&c.subProtocols.push(`mdg2auth-${this.#t}`)});const i=async c=>{this.hooks.callHook("frontgateConnection:setIdApp",he),this.hooks.callHook("frontgateConnection:setIdUser",be);const a={maximum_idle_interval:c.maximumIdleInterval},f={b64:this.#e},h=new qe(f,a.maximum_idle_interval).toJson();this.log(d.INFO,"Sending message",h);const v={message:h,callbackType:"response",callbackId:h.Message.replace("Request","Response")};await this.hooks.callHook("frontgateConnection:sendMessage",v),this.hooks.hookOnce(`frontgateConnection:response:${v.callbackId}`,m=>{this.log(d.INFO,"Received response",m),this.hooks.callHook("frontgateConnection:authenticated")})};this.hooks.hook("frontgateConnection:connected",i)}async#s(){const o=await fetch(this.#r,this.#n);if(!o.ok)throw new Error(`Failed to fetch connection configuration: ${o.status} ${o.statusText}`);const{headers:i}=o,c=i.get("frontgate-host"),a=i.get("frontgate-path-prefix"),f=i.get("frontgate-split-authentication-token-second-factor"),u=i.get("frontgate-authentication-type"),h=i.get("frontgate-authentication-token"),v=i.get("frontgate-websocket-port")??"443",m=`wss://${c}:${v}${a??""}/ws`;if(u==="token"&&!h)throw new Error("Authentication token is required for token authentication");if(u!=="token"&&!f)throw new Error("Split authentication token second factor is required");return{url:m,authtenticationType:u,authenticationToken:h,splitAuthenticationTokenSecondFactor:f}}},{featureName:"FetchAuth",featureGroups:["Auth","Connection"],disabledFeatureGroups:["Auth","Connection"]}),vn=r=>j(t=>class extends t{#e=0;#t;#r;constructor(...n){super(...n),this.#t=r??[1e3,2e3,4e3,8e3,16e3,32e3];const s=o=>{if(o.code!==1e3){this.#r&&(this.log(d.WARN,"Aborting previous reconnect attempt"),clearTimeout(this.#r),this.#e=0);let i=this.#e;this.#e>=this.#t.length&&(i=this.#t.length-1);const c=this.#t[i];this.#r=setTimeout(()=>{this.log(d.INFO,`Reconnecting... Attempt ${this.#e}`);const a=this.hooks.hookOnce("reconnect:failed",s);this.hooks.callHook("reconnect:attempt",o).then(a).catch(()=>{this.log(d.ERROR,"Failed to reconnect")}),this.#r=void 0},c),this.#e++}};this.hooks.hookOnce("frontgateConnection:disconnected",s),this.hooks.hook("reconnect:success",()=>{clearTimeout(this.#r),this.#r=void 0,this.#e=0,this.log(d.INFO,"Reconnected"),this.hooks.hookOnce("frontgateConnection:disconnected",s)})}},{featureName:"Reconnect",featureGroups:["Misc"],disabledFeatures:["TokenAuth","CookieTokenAuth"]});var bn=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof window=="object"?window:typeof global=="object"?global:{},ge="1.9.0",ur=/^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;function mn(r){var e=new Set([r]),t=new Set,n=r.match(ur);if(!n)return function(){return!1};var s={major:+n[1],minor:+n[2],patch:+n[3],prerelease:n[4]};if(s.prerelease!=null)return function(a){return a===r};function o(c){return t.add(c),!1}function i(c){return e.add(c),!0}return function(a){if(e.has(a))return!0;if(t.has(a))return!1;var f=a.match(ur);if(!f)return o(a);var u={major:+f[1],minor:+f[2],patch:+f[3],prerelease:f[4]};return u.prerelease!=null||s.major!==u.major?o(a):s.major===0?s.minor===u.minor&&s.patch<=u.patch?i(a):o(a):s.minor<=u.minor?i(a):o(a)}}var yn=mn(ge),wn=ge.split(".")[0],Ne=Symbol.for("opentelemetry.js.api."+wn),Se=bn;function Pe(r,e,t,n){var s;n===void 0&&(n=!1);var o=Se[Ne]=(s=Se[Ne])!==null&&s!==void 0?s:{version:ge};if(!n&&o[r]){var i=new Error("@opentelemetry/api: Attempted duplicate registration of API: "+r);return t.error(i.stack||i.message),!1}if(o.version!==ge){var i=new Error("@opentelemetry/api: Registration of version v"+o.version+" for "+r+" does not match previously registered API v"+ge);return t.error(i.stack||i.message),!1}return o[r]=e,t.debug("@opentelemetry/api: Registered a global for "+r+" v"+ge+"."),!0}function pe(r){var e,t,n=(e=Se[Ne])===null||e===void 0?void 0:e.version;if(!(!n||!yn(n)))return(t=Se[Ne])===null||t===void 0?void 0:t[r]}function xe(r,e){e.debug("@opentelemetry/api: Unregistering a global for "+r+" v"+ge+".");var t=Se[Ne];t&&delete t[r]}var kn=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),s,o=[],i;try{for(;(e===void 0||e-- >0)&&!(s=n.next()).done;)o.push(s.value)}catch(c){i={error:c}}finally{try{s&&!s.done&&(t=n.return)&&t.call(n)}finally{if(i)throw i.error}}return o},_n=function(r,e,t){if(t||arguments.length===2)for(var n=0,s=e.length,o;n<s;n++)(o||!(n in e))&&(o||(o=Array.prototype.slice.call(e,0,n)),o[n]=e[n]);return r.concat(o||Array.prototype.slice.call(e))},Mn=(function(){function r(e){this._namespace=e.namespace||"DiagComponentLogger"}return r.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Fe("debug",this._namespace,e)},r.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Fe("error",this._namespace,e)},r.prototype.info=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Fe("info",this._namespace,e)},r.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Fe("warn",this._namespace,e)},r.prototype.verbose=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Fe("verbose",this._namespace,e)},r})();function Fe(r,e,t){var n=pe("diag");if(n)return t.unshift(e),n[r].apply(n,_n([],kn(t),!1))}var B;(function(r){r[r.NONE=0]="NONE",r[r.ERROR=30]="ERROR",r[r.WARN=50]="WARN",r[r.INFO=60]="INFO",r[r.DEBUG=70]="DEBUG",r[r.VERBOSE=80]="VERBOSE",r[r.ALL=9999]="ALL"})(B||(B={}));function En(r,e){r<B.NONE?r=B.NONE:r>B.ALL&&(r=B.ALL),e=e||{};function t(n,s){var o=e[n];return typeof o=="function"&&r>=s?o.bind(e):function(){}}return{error:t("error",B.ERROR),warn:t("warn",B.WARN),info:t("info",B.INFO),debug:t("debug",B.DEBUG),verbose:t("verbose",B.VERBOSE)}}var Tn=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),s,o=[],i;try{for(;(e===void 0||e-- >0)&&!(s=n.next()).done;)o.push(s.value)}catch(c){i={error:c}}finally{try{s&&!s.done&&(t=n.return)&&t.call(n)}finally{if(i)throw i.error}}return o},In=function(r,e,t){if(t||arguments.length===2)for(var n=0,s=e.length,o;n<s;n++)(o||!(n in e))&&(o||(o=Array.prototype.slice.call(e,0,n)),o[n]=e[n]);return r.concat(o||Array.prototype.slice.call(e))},Rn="diag",re=(function(){function r(){function e(s){return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];var c=pe("diag");if(c)return c[s].apply(c,In([],Tn(o),!1))}}var t=this,n=function(s,o){var i,c,a;if(o===void 0&&(o={logLevel:B.INFO}),s===t){var f=new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");return t.error((i=f.stack)!==null&&i!==void 0?i:f.message),!1}typeof o=="number"&&(o={logLevel:o});var u=pe("diag"),h=En((c=o.logLevel)!==null&&c!==void 0?c:B.INFO,s);if(u&&!o.suppressOverrideMessage){var v=(a=new Error().stack)!==null&&a!==void 0?a:"<failed to generate stacktrace>";u.warn("Current logger will be overwritten from "+v),h.warn("Current logger will overwrite one already registered from "+v)}return Pe("diag",h,t,!0)};t.setLogger=n,t.disable=function(){xe(Rn,t)},t.createComponentLogger=function(s){return new Mn(s)},t.verbose=e("verbose"),t.debug=e("debug"),t.info=e("info"),t.warn=e("warn"),t.error=e("error")}return r.instance=function(){return this._instance||(this._instance=new r),this._instance},r})(),An=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),s,o=[],i;try{for(;(e===void 0||e-- >0)&&!(s=n.next()).done;)o.push(s.value)}catch(c){i={error:c}}finally{try{s&&!s.done&&(t=n.return)&&t.call(n)}finally{if(i)throw i.error}}return o},Cn=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},On=(function(){function r(e){this._entries=e?new Map(e):new Map}return r.prototype.getEntry=function(e){var t=this._entries.get(e);if(t)return Object.assign({},t)},r.prototype.getAllEntries=function(){return Array.from(this._entries.entries()).map(function(e){var t=An(e,2),n=t[0],s=t[1];return[n,s]})},r.prototype.setEntry=function(e,t){var n=new r(this._entries);return n._entries.set(e,t),n},r.prototype.removeEntry=function(e){var t=new r(this._entries);return t._entries.delete(e),t},r.prototype.removeEntries=function(){for(var e,t,n=[],s=0;s<arguments.length;s++)n[s]=arguments[s];var o=new r(this._entries);try{for(var i=Cn(n),c=i.next();!c.done;c=i.next()){var a=c.value;o._entries.delete(a)}}catch(f){e={error:f}}finally{try{c&&!c.done&&(t=i.return)&&t.call(i)}finally{if(e)throw e.error}}return o},r.prototype.clear=function(){return new r},r})();re.instance();function Nn(r){return r===void 0&&(r={}),new On(new Map(Object.entries(r)))}function hr(r){return Symbol.for(r)}var Sn=(function(){function r(e){var t=this;t._currentContext=e?new Map(e):new Map,t.getValue=function(n){return t._currentContext.get(n)},t.setValue=function(n,s){var o=new r(t._currentContext);return o._currentContext.set(n,s),o},t.deleteValue=function(n){var s=new r(t._currentContext);return s._currentContext.delete(n),s}}return r})(),Pn=new Sn,ve=(function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,s){n.__proto__=s}||function(n,s){for(var o in s)Object.prototype.hasOwnProperty.call(s,o)&&(n[o]=s[o])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}})(),xn=(function(){function r(){}return r.prototype.createGauge=function(e,t){return Bn},r.prototype.createHistogram=function(e,t){return Vn},r.prototype.createCounter=function(e,t){return Ln},r.prototype.createUpDownCounter=function(e,t){return Wn},r.prototype.createObservableGauge=function(e,t){return zn},r.prototype.createObservableCounter=function(e,t){return Jn},r.prototype.createObservableUpDownCounter=function(e,t){return Kn},r.prototype.addBatchObservableCallback=function(e,t){},r.prototype.removeBatchObservableCallback=function(e){},r})(),Ke=(function(){function r(){}return r})(),Fn=(function(r){ve(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e.prototype.add=function(t,n){},e})(Ke),$n=(function(r){ve(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e.prototype.add=function(t,n){},e})(Ke),Un=(function(r){ve(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e.prototype.record=function(t,n){},e})(Ke),Dn=(function(r){ve(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e.prototype.record=function(t,n){},e})(Ke),yt=(function(){function r(){}return r.prototype.addCallback=function(e){},r.prototype.removeCallback=function(e){},r})(),jn=(function(r){ve(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(yt),Hn=(function(r){ve(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(yt),Gn=(function(r){ve(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(yt),qn=new xn,Ln=new Fn,Bn=new Un,Vn=new Dn,Wn=new $n,Jn=new jn,zn=new Hn,Kn=new Gn,Yn={get:function(r,e){if(r!=null)return r[e]},keys:function(r){return r==null?[]:Object.keys(r)}},Qn={set:function(r,e,t){r!=null&&(r[e]=t)}},Xn=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),s,o=[],i;try{for(;(e===void 0||e-- >0)&&!(s=n.next()).done;)o.push(s.value)}catch(c){i={error:c}}finally{try{s&&!s.done&&(t=n.return)&&t.call(n)}finally{if(i)throw i.error}}return o},Zn=function(r,e,t){if(t||arguments.length===2)for(var n=0,s=e.length,o;n<s;n++)(o||!(n in e))&&(o||(o=Array.prototype.slice.call(e,0,n)),o[n]=e[n]);return r.concat(o||Array.prototype.slice.call(e))},es=(function(){function r(){}return r.prototype.active=function(){return Pn},r.prototype.with=function(e,t,n){for(var s=[],o=3;o<arguments.length;o++)s[o-3]=arguments[o];return t.call.apply(t,Zn([n],Xn(s),!1))},r.prototype.bind=function(e,t){return t},r.prototype.enable=function(){return this},r.prototype.disable=function(){return this},r})(),ts=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),s,o=[],i;try{for(;(e===void 0||e-- >0)&&!(s=n.next()).done;)o.push(s.value)}catch(c){i={error:c}}finally{try{s&&!s.done&&(t=n.return)&&t.call(n)}finally{if(i)throw i.error}}return o},rs=function(r,e,t){if(t||arguments.length===2)for(var n=0,s=e.length,o;n<s;n++)(o||!(n in e))&&(o||(o=Array.prototype.slice.call(e,0,n)),o[n]=e[n]);return r.concat(o||Array.prototype.slice.call(e))},wt="context",ns=new es,Ye=(function(){function r(){}return r.getInstance=function(){return this._instance||(this._instance=new r),this._instance},r.prototype.setGlobalContextManager=function(e){return Pe(wt,e,re.instance())},r.prototype.active=function(){return this._getContextManager().active()},r.prototype.with=function(e,t,n){for(var s,o=[],i=3;i<arguments.length;i++)o[i-3]=arguments[i];return(s=this._getContextManager()).with.apply(s,rs([e,t,n],ts(o),!1))},r.prototype.bind=function(e,t){return this._getContextManager().bind(e,t)},r.prototype._getContextManager=function(){return pe(wt)||ns},r.prototype.disable=function(){this._getContextManager().disable(),xe(wt,re.instance())},r})(),kt;(function(r){r[r.NONE=0]="NONE",r[r.SAMPLED=1]="SAMPLED"})(kt||(kt={}));var lr="0000000000000000",fr="00000000000000000000000000000000",ss={traceId:fr,spanId:lr,traceFlags:kt.NONE},$e=(function(){function r(e){e===void 0&&(e=ss),this._spanContext=e}return r.prototype.spanContext=function(){return this._spanContext},r.prototype.setAttribute=function(e,t){return this},r.prototype.setAttributes=function(e){return this},r.prototype.addEvent=function(e,t){return this},r.prototype.addLink=function(e){return this},r.prototype.addLinks=function(e){return this},r.prototype.setStatus=function(e){return this},r.prototype.updateName=function(e){return this},r.prototype.end=function(e){},r.prototype.isRecording=function(){return!1},r.prototype.recordException=function(e,t){},r})(),_t=hr("OpenTelemetry Context Key SPAN");function Mt(r){return r.getValue(_t)||void 0}function os(){return Mt(Ye.getInstance().active())}function Et(r,e){return r.setValue(_t,e)}function is(r){return r.deleteValue(_t)}function as(r,e){return Et(r,new $e(e))}function dr(r){var e;return(e=Mt(r))===null||e===void 0?void 0:e.spanContext()}var cs=/^([0-9a-f]{32})$/i,us=/^[0-9a-f]{16}$/i;function hs(r){return cs.test(r)&&r!==fr}function ls(r){return us.test(r)&&r!==lr}function gr(r){return hs(r.traceId)&&ls(r.spanId)}function fs(r){return new $e(r)}var Tt=Ye.getInstance(),pr=(function(){function r(){}return r.prototype.startSpan=function(e,t,n){n===void 0&&(n=Tt.active());var s=!!t?.root;if(s)return new $e;var o=n&&dr(n);return ds(o)&&gr(o)?new $e(o):new $e},r.prototype.startActiveSpan=function(e,t,n,s){var o,i,c;if(!(arguments.length<2)){arguments.length===2?c=t:arguments.length===3?(o=t,c=n):(o=t,i=n,c=s);var a=i??Tt.active(),f=this.startSpan(e,o,a),u=Et(a,f);return Tt.with(u,c,void 0,f)}},r})();function ds(r){return typeof r=="object"&&typeof r.spanId=="string"&&typeof r.traceId=="string"&&typeof r.traceFlags=="number"}var gs=new pr,ps=(function(){function r(e,t,n,s){this._provider=e,this.name=t,this.version=n,this.options=s}return r.prototype.startSpan=function(e,t,n){return this._getTracer().startSpan(e,t,n)},r.prototype.startActiveSpan=function(e,t,n,s){var o=this._getTracer();return Reflect.apply(o.startActiveSpan,o,arguments)},r.prototype._getTracer=function(){if(this._delegate)return this._delegate;var e=this._provider.getDelegateTracer(this.name,this.version,this.options);return e?(this._delegate=e,this._delegate):gs},r})(),vs=(function(){function r(){}return r.prototype.getTracer=function(e,t,n){return new pr},r})(),bs=new vs,vr=(function(){function r(){}return r.prototype.getTracer=function(e,t,n){var s;return(s=this.getDelegateTracer(e,t,n))!==null&&s!==void 0?s:new ps(this,e,t,n)},r.prototype.getDelegate=function(){var e;return(e=this._delegate)!==null&&e!==void 0?e:bs},r.prototype.setDelegate=function(e){this._delegate=e},r.prototype.getDelegateTracer=function(e,t,n){var s;return(s=this._delegate)===null||s===void 0?void 0:s.getTracer(e,t,n)},r})();Ye.getInstance(),re.instance();var ms=(function(){function r(){}return r.prototype.getMeter=function(e,t,n){return qn},r})(),ys=new ms,It="metrics",ws=(function(){function r(){}return r.getInstance=function(){return this._instance||(this._instance=new r),this._instance},r.prototype.setGlobalMeterProvider=function(e){return Pe(It,e,re.instance())},r.prototype.getMeterProvider=function(){return pe(It)||ys},r.prototype.getMeter=function(e,t,n){return this.getMeterProvider().getMeter(e,t,n)},r.prototype.disable=function(){xe(It,re.instance())},r})();ws.getInstance();var ks=(function(){function r(){}return r.prototype.inject=function(e,t){},r.prototype.extract=function(e,t){return e},r.prototype.fields=function(){return[]},r})(),Rt=hr("OpenTelemetry Baggage Key");function br(r){return r.getValue(Rt)||void 0}function _s(){return br(Ye.getInstance().active())}function Ms(r,e){return r.setValue(Rt,e)}function Es(r){return r.deleteValue(Rt)}var At="propagation",Ts=new ks,Is=(function(){function r(){this.createBaggage=Nn,this.getBaggage=br,this.getActiveBaggage=_s,this.setBaggage=Ms,this.deleteBaggage=Es}return r.getInstance=function(){return this._instance||(this._instance=new r),this._instance},r.prototype.setGlobalPropagator=function(e){return Pe(At,e,re.instance())},r.prototype.inject=function(e,t,n){return n===void 0&&(n=Qn),this._getGlobalPropagator().inject(e,t,n)},r.prototype.extract=function(e,t,n){return n===void 0&&(n=Yn),this._getGlobalPropagator().extract(e,t,n)},r.prototype.fields=function(){return this._getGlobalPropagator().fields()},r.prototype.disable=function(){xe(At,re.instance())},r.prototype._getGlobalPropagator=function(){return pe(At)||Ts},r})();Is.getInstance();var Ct="trace",Rs=(function(){function r(){this._proxyTracerProvider=new vr,this.wrapSpanContext=fs,this.isSpanContextValid=gr,this.deleteSpan=is,this.getSpan=Mt,this.getActiveSpan=os,this.getSpanContext=dr,this.setSpan=Et,this.setSpanContext=as}return r.getInstance=function(){return this._instance||(this._instance=new r),this._instance},r.prototype.setGlobalTracerProvider=function(e){var t=Pe(Ct,this._proxyTracerProvider,re.instance());return t&&this._proxyTracerProvider.setDelegate(e),t},r.prototype.getTracerProvider=function(){return pe(Ct)||this._proxyTracerProvider},r.prototype.getTracer=function(e,t){return this.getTracerProvider().getTracer(e,t)},r.prototype.disable=function(){xe(Ct,re.instance()),this._proxyTracerProvider=new vr},r})(),As=Rs.getInstance();const Cs=()=>j(e=>class extends e{constructor(...t){super(...t),this.hooks.hook("frontgateConnection:beforeSerializeMessage",n=>{n.header&&As.getTracer("frontgate-js-sdk").startActiveSpan("frontgateConnection:sendMessage",s=>{const o=this.#e(s.spanContext());o&&(n.header={...n.header,...o}),s.end()})})}#e(t){if(!/^0+$/.test(t.traceId))return{tracing:{value:{value:mr(t)}}}}},{featureName:"OpenTelemetry",featureGroups:["Misc"]}),mr=r=>{const e=[18,20,9],t=n=>{for(let s=n.length;s>n.length-16;s-=2){let o=parseInt(n.substring(s-2,s),16);o>127&&(o-=256),e.push(o)}};return t(r.traceId),e.push(17),t(r.spanId),e.push(24),e.push(0),e},Os=()=>j(e=>class extends e{async requestProxyEndpoint(t,n,s,o,i=this.defaultTimeoutInMs){const c=new Be(t,n,o);s&&c.setBody(s),c.header.setTimeout(i);const a={message:c.getPtlMessage(),callbackType:"job",callbackId:""};await this.hooks.callHook("frontgateConnection:sendMessage",a);const f=new Promise((h,v)=>{this.hooks.hookOnce(`frontgateConnection:response:${a.callbackId}`,m=>{try{if(!m.Message.includes("HTTPProxyResponse")){v(JSON.stringify(m));return}const M=new Jt(m);h({response:M,data:M.data})}catch(M){v(M)}})}),u=`Request timeout reached (${i} ms) for ${a.message.Message}`;return Y(i,u,f)}},{featureName:"HTTPProxyRequest",featureGroups:["Misc"]}),Ns=()=>j(e=>class extends e{async ping(t=this.defaultTimeoutInMs){const s={message:new Ve().getPtlMessage(),callbackType:"response",callbackId:"PingResponse"};await this.hooks.callHook("frontgateConnection:sendMessage",s);const o=new Promise(c=>{this.hooks.hookOnce(`frontgateConnection:response:${s.callbackId}`,a=>{const f=new We(a);c(f)})}),i=`Request timeout reached (${t} ms) for ${s.message.Message}`;return Y(t,i,o)}},{featureName:"Pingable",featureGroups:["Misc"]}),Ss=r=>j(t=>class extends t{async logRemotely(n){const o={message:new Bt({Message:"LogMessage",timestamp:{microseconds:Date.now()*1e3},uuid:{id_1:r??0,id_2:0},level:{value:4},area:61,Version:1,message:n}).getPtlMessage(),callbackType:"job",callbackId:""};return this.hooks.callHook("frontgateConnection:sendMessage",o)}},{featureName:"RemoteLogger",featureGroups:["Misc"]}),j=(r,e)=>{const t=r;return t.featureName=e.featureName,t.featureGroups=e.featureGroups,t.disabledFeatures=e.disabledFeatures,t.disabledFeatureGroups=e.disabledFeatureGroups,t};function Ot(r,e={},t){for(const n in r){const s=r[n],o=t?`${t}:${n}`:n;typeof s=="object"&&s!==null?Ot(s,e,o):typeof s=="function"&&(e[o]=s)}return e}const Ps={run:r=>r()},xs=()=>Ps,yr=typeof console.createTask<"u"?console.createTask:xs;function Fs(r,e){const t=e.shift(),n=yr(t);return r.reduce((s,o)=>s.then(()=>n.run(()=>o(...e))),Promise.resolve())}function $s(r,e){const t=e.shift(),n=yr(t);return Promise.all(r.map(s=>n.run(()=>s(...e))))}function Nt(r,e){for(const t of[...r])t(e)}class Us{constructor(){this._hooks={},this._before=void 0,this._after=void 0,this._deprecatedMessages=void 0,this._deprecatedHooks={},this.hook=this.hook.bind(this),this.callHook=this.callHook.bind(this),this.callHookWith=this.callHookWith.bind(this)}hook(e,t,n={}){if(!e||typeof t!="function")return()=>{};const s=e;let o;for(;this._deprecatedHooks[e];)o=this._deprecatedHooks[e],e=o.to;if(o&&!n.allowDeprecated){let i=o.message;i||(i=`${s} hook has been deprecated`+(o.to?`, please use ${o.to}`:"")),this._deprecatedMessages||(this._deprecatedMessages=new Set),this._deprecatedMessages.has(i)||(console.warn(i),this._deprecatedMessages.add(i))}if(!t.name)try{Object.defineProperty(t,"name",{get:()=>"_"+e.replace(/\W+/g,"_")+"_hook_cb",configurable:!0})}catch{}return this._hooks[e]=this._hooks[e]||[],this._hooks[e].push(t),()=>{t&&(this.removeHook(e,t),t=void 0)}}hookOnce(e,t){let n,s=(...o)=>(typeof n=="function"&&n(),n=void 0,s=void 0,t(...o));return n=this.hook(e,s),n}removeHook(e,t){if(this._hooks[e]){const n=this._hooks[e].indexOf(t);n!==-1&&this._hooks[e].splice(n,1),this._hooks[e].length===0&&delete this._hooks[e]}}deprecateHook(e,t){this._deprecatedHooks[e]=typeof t=="string"?{to:t}:t;const n=this._hooks[e]||[];delete this._hooks[e];for(const s of n)this.hook(e,s)}deprecateHooks(e){Object.assign(this._deprecatedHooks,e);for(const t in e)this.deprecateHook(t,e[t])}addHooks(e){const t=Ot(e),n=Object.keys(t).map(s=>this.hook(s,t[s]));return()=>{for(const s of n.splice(0,n.length))s()}}removeHooks(e){const t=Ot(e);for(const n in t)this.removeHook(n,t[n])}removeAllHooks(){for(const e in this._hooks)delete this._hooks[e]}callHook(e,...t){return t.unshift(e),this.callHookWith(Fs,e,...t)}callHookParallel(e,...t){return t.unshift(e),this.callHookWith($s,e,...t)}callHookWith(e,t,...n){const s=this._before||this._after?{name:t,args:n,context:{}}:void 0;this._before&&Nt(this._before,s);const o=e(t in this._hooks?[...this._hooks[t]]:[],n);return o instanceof Promise?o.finally(()=>{this._after&&s&&Nt(this._after,s)}):(this._after&&s&&Nt(this._after,s),o)}beforeEach(e){return this._before=this._before||[],this._before.push(e),()=>{if(this._before!==void 0){const t=this._before.indexOf(e);t!==-1&&this._before.splice(t,1)}}}afterEach(e){return this._after=this._after||[],this._after.push(e),()=>{if(this._after!==void 0){const t=this._after.indexOf(e);t!==-1&&this._after.splice(t,1)}}}}function Ds(){return new Us}const wr=typeof window<"u";function js(r,e={}){const t={inspect:wr,group:wr,filter:()=>!0,...e},n=t.filter,s=typeof n=="string"?u=>u.startsWith(n):n,o=t.tag?`[${t.tag}] `:"",i=u=>o+u.name+"".padEnd(u._id,"\0"),c={},a=r.beforeEach(u=>{s!==void 0&&!s(u.name)||(c[u.name]=c[u.name]||0,u._id=c[u.name]++,console.time(i(u)))}),f=r.afterEach(u=>{s!==void 0&&!s(u.name)||(t.group&&console.groupCollapsed(u.name),t.inspect?console.timeLog(i(u),u.args):console.timeEnd(i(u)),t.group&&console.groupEnd(),c[u.name]--)});return{close:()=>{a(),f()}}}class kr{constructor(e){this.hooks=Ds(),this.#e=1e4,e?.hookDebug&&js(this.hooks,{tag:"hooks"}),e?.defaultRequestTimeout&&(this.#e=e.defaultRequestTimeout)}#e;get defaultTimeoutInMs(){return this.#e}log(e,...t){if(this.hooks.callHook("base:log",t),this.logger)switch(e){case d.TRACE:this.logger.trace(t);break;case d.DEBUG:this.logger.debug(t);break;case d.INFO:this.logger.info(t);break;case d.WARN:this.logger.warn(t);break;case d.ERROR:this.logger.error(t);break;case d.FATAL:this.logger.fatal(t);break}}}class Qe{#e;#t=[];#r=[];#n=[];constructor(e,t=[],n=[],s=[]){this.#e=e,this.#t=t,this.#r=n,this.#n=s}static create(){return new Qe(kr)}#s(e){if(this.#t.includes(e))throw new Error(`Feature "${e}" has already been used.`)}#i(e){for(const t of this.#r)if(t.feature===e)throw new Error(`Feature "${e}" has been disabled by ${t.disabler.join(",")}.`)}#a(e){for(const t of this.#n)if(t.feature===e)throw new Error(`Group "${e}" has been disabled by ${t.disabler.join(",")}.`)}#o(e,t){for(const n of this.#r)if(n.feature===t){n.disabler.push(e);return}this.#r.push({disabler:[e],feature:t})}#c(e,t){for(const n of this.#n)if(n.feature===t){n.disabler.push(e);return}this.#n.push({disabler:[e],feature:t})}with(e){const{featureName:t,disabledFeatures:n,disabledFeatureGroups:s,featureGroups:o}=e;if(!t)throw new Error("Feature name is missing");if(t!=="Custom"){if(this.#s(t),this.#i(t),this.#t.push(t),o&&o.length>0)for(const c of o)this.#a(c);if(n&&n.length>0)for(const c of n)this.#o(t,c);if(s&&s.length>0)for(const c of s)this.#c(t,c)}const i=e(this.#e);return new Qe(i,this.#t,this.#r,this.#n)}build(e){return new this.#e(e)}getClientConstructor(){return this.#e}}b.AbstractLogger=ie,b.AbstractMdg2Request=me,b.AuthenticationByTokenRequest=qe,b.AuthenticationTokenRequest=Le,b.AuthenticationTokenResponse=Vt,b.CancelSubscriptionRequest=ye,b.ConnectionState=Ut,b.ConsoleLogger=nt,b.CookieTokenAuthenticationFactors=Ft,b.DEFAULT_TIMEOUT_IN_MS=Lt,b.DefaultHosts=jt,b.DeploymentStage=Dt,b.ErrorResponse=z,b.FLAG_HAS_NEXT_CHUNK=rt,b.FrontgateClient=kr,b.FrontgateClientBuilder=Qe,b.FrontgateClientDataObserver=mt,b.FrontgateClientEndpointDataObserver=cr,b.HTTPProxyRequest=Be,b.HTTPProxyResponse=Jt,b.HighLevelRequest=we,b.HighLevelResponse=Wt,b.HighLevelUpdate=tt,b.ID_APP_AUTHENTICATED=he,b.ID_USER_AUTHENTICATED=be,b.ID_USER_NONE=$t,b.LogLevel=d,b.LoggerHelper=Sr,b.Mdg2Response=le,b.NullLogger=st,b.PingRequest=Ve,b.PingResponse=We,b.RawRequest=Bt,b.TimeOptions=Ht,b.TransportLayerClientRequestHeader=Ge,b.WinstonLogger=xr,b.authTokenRequest=Fr,b.cookieTokenAuth=dn,b.createExtendedMixinFactory=j,b.encodeSpanContext=mr,b.endpointRequest=$r,b.endpointSubscriptions=on,b.fetchAuth=pn,b.getBytesFromBuffer=Rr,b.httpProxyRequest=Os,b.levels=Pr,b.logger=Ur,b.messageCompressor=nn,b.openTelemetry=Cs,b.pingRequests=Ns,b.rawSubscriptions=an,b.reconnect=vn,b.remotelogger=Ss,b.requests=sn,b.timeToMilliseconds=He,b.tokenAuth=gn,b.useTimeout=Y,b.wsConnection=zt,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(b,Ce){typeof exports=="object"&&typeof module<"u"?Ce(exports):typeof define=="function"&&define.amd?define(["exports"],Ce):(b=typeof globalThis<"u"?globalThis:b||self,Ce(b.fdsg={}))})(this,(function(b){"use strict";function Ce(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var et,xt;function Mr(){if(xt)return et;xt=1;var r=function(v){return e(v)&&!t(v)};function e(d){return!!d&&typeof d=="object"}function t(d){var v=Object.prototype.toString.call(d);return v==="[object RegExp]"||v==="[object Date]"||s(d)}var n=typeof Symbol=="function"&&Symbol.for,o=n?Symbol.for("react.element"):60103;function s(d){return d.$$typeof===o}function i(d){return Array.isArray(d)?[]:{}}function c(d,v){return v.clone!==!1&&v.isMergeableObject(d)?T(i(d),d,v):d}function a(d,v,g){return d.concat(v).map(function(w){return c(w,g)})}function l(d,v){if(!v.customMerge)return T;var g=v.customMerge(d);return typeof g=="function"?g:T}function u(d){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(d).filter(function(v){return Object.propertyIsEnumerable.call(d,v)}):[]}function h(d){return Object.keys(d).concat(u(d))}function p(d,v){try{return v in d}catch{return!1}}function m(d,v){return p(d,v)&&!(Object.hasOwnProperty.call(d,v)&&Object.propertyIsEnumerable.call(d,v))}function M(d,v,g){var w={};return g.isMergeableObject(d)&&h(d).forEach(function(y){w[y]=c(d[y],g)}),h(v).forEach(function(y){m(d,y)||(p(d,y)&&g.isMergeableObject(v[y])?w[y]=l(y,g)(d[y],v[y],g):w[y]=c(v[y],g))}),w}function T(d,v,g){g=g||{},g.arrayMerge=g.arrayMerge||a,g.isMergeableObject=g.isMergeableObject||r,g.cloneUnlessOtherwiseSpecified=c;var w=Array.isArray(v),y=Array.isArray(d),I=w===y;return I?w?g.arrayMerge(d,v,g):M(d,v,g):c(v,g)}T.all=function(v,g){if(!Array.isArray(v))throw new Error("first argument should be an array");return v.reduce(function(w,y){return T(w,y,g)},{})};var _=T;return et=_,et}var Er=Mr();const Ft=Ce(Er);function Tr(r){return!!r&&typeof r=="object"}function Ir(...r){const e=r.filter(Tr);return Ft.all(e,{arrayMerge:(t,n)=>n})}function Cr(r){return r.replace(/[=]/g,"").replace(/\//g,"_").replace(/\+/g,"-")}class $t{constructor(e){const t=Cr(e),n=Math.ceil(t.length/2);this.firstFactor=t.substring(0,n),this.secondFactor=t.substring(n)}getFirstFactor(){return this.firstFactor}getSecondFactor(){return this.secondFactor}}const oe=-2,ae=-2,Ut=-1;function Ar(r){const e=[];if(r)for(let t=0;t<r.length;t++)e.push(r.readInt8(t));return e}var Dt=(r=>(r[r.DISCONNECTED=0]="DISCONNECTED",r[r.CONNECTING=1]="CONNECTING",r[r.AUTHENTICATED=2]="AUTHENTICATED",r[r.RECONNECTING=3]="RECONNECTING",r))(Dt||{}),jt=(r=>(r[r.production=40]="production",r[r.preproduction=35]="preproduction",r[r.show=30]="show",r[r.testing=20]="testing",r))(jt||{}),Ht=(r=>(r.production="frontgate-eu.factsetdigitalsolutions.com",r.show="frontgate-eu.show.factsetdigitalsolutions.com",r))(Ht||{}),Gt=(r=>(r.MAXIMUM_STRING="9223372036854775807",r.MINIMUM_STRING="-9223372036854775807",r))(Gt||{});function Ge(r){return r.toString().slice(0,-3)}const qt={version:"7.1.0",package:"@factset/frontgate-js-sdk"};function Rr(){const r=Or();return{userAgent:r.userAgent??"unknown",platform:"frontgate-js-sdk",version:qt.version,package:qt.package,mobile:/Mobi/i.test(r.userAgent??"unknown")}}function Or(){return typeof navigator<"u"?navigator:typeof process<"u"?{userAgent:`node.js/io.js, ${process.version}`}:{userAgent:"unknown"}}const Nr=r=>{const e=[18,20,9],t=n=>{for(let o=n.length;o>n.length-16;o-=2){let s=parseInt(n.substring(o-2,o),16);s>127&&(s-=256),e.push(s)}};return t(r.traceId),e.push(17),t(r.spanId),e.push(24),e.push(0),e},Sr=async(r,e)=>new Promise((t,n)=>{setTimeout(()=>{n(e)},r)}),Y=async(r,e,t)=>Promise.race([Sr(r,e),t]),Lt=r=>r+Math.random()*100,Bt=6e3,X=class X{constructor(){this.headerMembers={dataset:{id_dataset:0},id_job:0,flags_r2:0,resend_counter:0,timeout:Bt,authentication_identifiers:{id_application:0,id_user:0},cache_key:{value:[]},previous_response_hash:{value:[]},tracing:{value:{value:[]}}},this.flags=[]}getPtlMessage(){return this.headerMembers}getQuality(){return Object.keys(X.PRICE_QUALITY).find(t=>X.PRICE_QUALITY[t]===this.headerMembers.dataset.id_dataset)}setQuality(e){this.headerMembers.dataset.id_dataset=X.PRICE_QUALITY[e]}setIdApplication(e,t=!1){(this.headerMembers.authentication_identifiers.id_application===0||t)&&(this.headerMembers.authentication_identifiers.id_application=e)}setIdUser(e,t=!1){(this.headerMembers.authentication_identifiers.id_user===0||t)&&(this.headerMembers.authentication_identifiers.id_user=e)}setFlag(e,t=!0){const n=this.flags.indexOf(e);t&&n===-1&&this.flags.push(e),!t&&n>-1&&this.flags.splice(n,1),this.headerMembers.flags_r2=this.getFlagsValue()}getFlagsValue(){return this.flags.reduce((e,t)=>e+X.FLAG_VALUE[t],0)}isFlagValueSet(e){return this.flags.find(t=>t===e)!==void 0}setJobId(e){this.headerMembers.id_job=e}getJobId(){return this.headerMembers.id_job}countResend(){this.headerMembers.resend_counter++}getResendCounter(){return this.headerMembers.resend_counter}setTimeout(e){if(e>0){this.headerMembers.timeout=e;return}throw new Error(`Attempted to set the timeout to "${e}". The timeout must be greater than 0.`)}getTimeout(){return this.headerMembers.timeout}setTracing(e){/^0+$/.test(e.traceId)||(this.headerMembers.tracing.value.value=Nr(e))}static getDataSet(e){return Object.prototype.hasOwnProperty.call(X.PRICE_QUALITY,e)?X.PRICE_QUALITY[e]:X.PRICE_QUALITY.DLY}};X.PRICE_QUALITY={RLT:129,DLY:0,EOD:130},X.FLAG_VALUE={add_subscription:1,no_merge:2,support_caching:4,permission_denied_response:8,internal_client:16,current_state_refresh:32,subscription_use_pull_permissions:64,allow_chunked_response:128};let qe=X;class me{constructor(e,t){this.header=new qe,this.coreMembers={Message:e,Version:t},this.members={}}getPtlMessage(){const e={header:this.header.getPtlMessage()};return Ir(this.coreMembers,e,this.members)}}class Ae{constructor(e,t){this.token=e,this.maximumIdleInterval=t}toJson(){const e=Rr();return{Message:"AuthenticationByTokenRequest",Version:1,token:{value:this.token},software:JSON.stringify(e),os:e.platform,feature_flags_wanted:{value:0},maximum_idle_interval:this.maximumIdleInterval,maximum_receivable_message_size:1048576,flags:0,cache_authentication_salt:{value:[]},cache_authentication_encrypted_secret:{encrypted_secret:[]}}}}const Z=class Z extends me{constructor(e,t,n,o,s=!1){super(Z.NAME,Z.VERSION),t&&this.header.setIdUser(t),n&&this.header.setIdApplication(n),o&&this.header.setTimeout(o),this.members.flags=s?Z.FLAG_SINGLE_USAGE:0,this.members.lifetime_seconds_r2=e??Z.LIFETIME_SECONDS_DEFAULT,this.header.setFlag("no_merge")}};Z.NAME="AuthenticationTokenRequest",Z.VERSION=6,Z.LIFETIME_SECONDS_DEFAULT=-1,Z.LIFETIME_SECONDS_MAXIMUM=-2,Z.FLAG_SINGLE_USAGE=1;let Le=Z;const we=class we extends me{constructor(e){super(we.NAME,we.VERSION),this.members.id_job_subscription=e}};we.NAME="CancelSubscriptionRequest",we.VERSION=6;let ye=we;const ee=class ee extends me{constructor(e,t,n={},o){super(ee.NAME,ee.VERSION),this.members.accept="application/json",this.members.content_type="application/json",this.members.body={value:[]},this.members.query="",this.members.path=t,this.setMethod(e),Object.keys(n).length>0&&(e==="POST"?this.setBody(n):this.setQuery(n)),o&&this.setOptions(o)}setOptions(e){Object.hasOwnProperty.call(e,"accept")&&(this.members.accept=e.accept),Object.hasOwnProperty.call(e,"content_type")&&(this.members.content_type=e.content_type),Object.hasOwnProperty.call(e,"subscribe")&&e.subscribe&&this.header.setFlag("add_subscription"),Object.hasOwnProperty.call(e,"no_merge")&&e.no_merge&&this.header.setFlag("no_merge"),Object.hasOwnProperty.call(e,"allowChunkedResponse")&&e.allowChunkedResponse&&this.header.setFlag("allow_chunked_response"),Object.hasOwnProperty.call(e,"idApplication")&&e.idApplication&&this.header.setIdApplication(e.idApplication),Object.hasOwnProperty.call(e,"idUser")&&e.idUser&&this.header.setIdUser(e.idUser)}setMethod(e){const t=e==="POST"?ee.METHOD.POST:ee.METHOD.GET;this.members.method={value:t}}setBody(e={}){e instanceof Array?this.members.body={value:e}:this.members.body={value:JSON.stringify(e)}}getData(){return this.members.method.value===ee.METHOD.POST?ee.ptlToJsonData(this.members.body.value):this.members.query}setQuery(e={}){this.members.query=Object.keys(e).map(t=>`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`).join("&")}static ptlToJsonData(e){if(typeof e=="string")return JSON.parse(e);if(e instanceof Array&&e.length>0){let t="";return e.forEach(n=>{t+=String.fromCharCode(n)}),JSON.parse(t)}}};ee.NAME="HighLevelRequest",ee.VERSION=3,ee.METHOD={GET:1,POST:2};let ke=ee;const V=class V extends me{constructor(e,t,n){super(V.NAME,V.VERSION),this.members.request={headers:{values:[{key:"accept",value:"application/json"},{key:"content-type",value:"application/json"}]},protocol:{value:V.PROTOCOL.HTTPS},host:"",port:0,path:t,query:"",body:{value:[]}},this.setQuery(),this.setMethod(e),n&&this.setOptions(n)}setOptions(e){e.no_merge&&this.header.setFlag("no_merge"),e.idApplication&&this.header.setIdApplication(e.idApplication),e.idUser&&this.header.setIdUser(e.idUser),e.protocol&&(this.members.request.protocol=e.protocol.toUpperCase()==="HTTP"?{value:V.PROTOCOL.HTTP}:{value:V.PROTOCOL.HTTPS}),e.method&&(this.members.request.method={value:V.METHOD[e.method]}),e.host&&(this.members.request.host=e.host),e.port&&(this.members.request.port=e.port),e.path&&(this.members.request.path=e.path),e.query&&(this.members.request.query=typeof e.query=="string"?e.query:Object.keys(e.query).map(t=>`${encodeURIComponent(t)}=${encodeURIComponent(e.query[t])}`).join("&")),e.body&&this.setBody(e.body),e.headers&&this.setHeaders(e.headers)}setHeaders(e){for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)){const n=e[t],o=this.members.request.headers.values.findIndex(i=>i.key===t);o!==-1&&this.members.request.headers.values.splice(o,1),this.members.request.headers.values.push({key:t,value:n})}}setQuery(){if(this.members.request.path.includes("?")){const e=this.members.request.path.split("?");this.members.request.path=e[0],this.members.request.query=e[1]}}setMethod(e){this.members.request.method={value:V.METHOD[e]}}setBody(e={}){return e instanceof Array||typeof e=="string"?this.members.request.body={value:e}:this.members.request.body={value:JSON.stringify(e)},this}getData(){if(this.members.request.body?.value)return ke.ptlToJsonData(this.members.request.body.value)}};V.NAME="HTTPProxyRequest",V.VERSION=2,V.PROTOCOL={HTTP:1,HTTPS:2},V.METHOD={GET:1,POST:2,OPTIONS:3,HEAD:4,PUT:5,DELETE:6,TRACE:7,CONNECT:8};let Be=V;const _e=class _e{constructor(){this._timeAtSender=Date.now()}getPtlMessage(){return{Message:_e.NAME,Version:_e.VERSION,time_at_sender:{microseconds:this._timeAtSender*1e3}}}resetTimeAtSender(){this._timeAtSender=Date.now()}get timeAtSender(){return this._timeAtSender}};_e.NAME="PingRequest",_e.VERSION=3;let Ve=_e;class Vt extends me{constructor(e){super(e.Message,e.version?e.version:e.Version),this._extractRequestAttributes(e)}_extractRequestAttributes(e){for(const t of Object.keys(this.coreMembers))delete e[t];this.members=Ft(this.members,e)}}class fe{constructor(e){this.raw=e}get msg(){return this.raw}get name(){return this.raw.Message}get jobId(){return this.raw.header.id_job}get serviceId(){return this.raw.header.id_service}isUpdateMessage(){return Object.hasOwnProperty.call(this.raw,"header")?(Object.hasOwnProperty.call(this.raw.header,"id_service")||Object.hasOwnProperty.call(this.raw.header,"id_job"))&&this.raw.Message.endsWith("Update"):!1}isLossMessage(){return Object.hasOwnProperty.call(this.raw,"header")?(Object.hasOwnProperty.call(this.raw.header,"id_service")||Object.hasOwnProperty.call(this.raw.header,"id_job"))&&(this.raw.Message.endsWith("LossMessage")||this.raw.Message.endsWith("Loss")):!1}}class Wt extends fe{constructor(e){if(super(e),!this.raw.token.value.b64)throw new Error("Token not set in AuthenticationTokenResponse");if(!this.raw.expiry.microseconds)throw new Error("Expiry not set in AuthenticationTokenResponse");this.token=this.raw.token.value.b64,this.expiry=parseInt(Ge(this.raw.expiry.microseconds),10)}getToken(){return this.token}getExpiry(){return this.expiry}}class z extends fe{get reason(){return this.raw.details}get jobId(){return this.raw.id_job}}class Jt extends fe{constructor(e){super(e);try{this.responseData=JSON.parse(this.raw.body.value)}catch(t){throw new Error(`Could not parse HighLevelResponse: ${t.message}`)}}get data(){return this.responseData.data}get meta(){return this.responseData.meta}get status(){return this.meta.status}get statusCode(){return this.status.code}}class zt extends fe{constructor(e){super(e);try{const t=this.raw.response.body.value,n=t.substr(0,1)==="{";this.responseData=n?JSON.parse(t):t}catch(t){throw new Error(`Could not parse HTTPProxyResponse: ${t}`)}this.responseInfo=this.raw.info,this.statusReason=this.raw.response.status_reason,this.statusCode=this.raw.response.status_code.value}get data(){return this.responseData}get meta(){return this.responseData.meta}get status(){return{code:this.statusCode,reason:this.statusReason}}}const Me=class Me{constructor(e){if(e.Message!==Me.NAME)throw new Error(`Unsupported message=${e.Message}`);if(e.Version!==Me.VERSION)throw new Error(`Unsupported version=${e.Version} for message=${e.Message}`);this._timeReceivedResponse=Date.now(),this._timeAtSender=Number(Ge(e.time_at_sender.microseconds)),this._timeFromRequest=Number(Ge(e.time_from_request.microseconds))}get timeAtPeer(){return this._timeAtSender}get timeOfRequest(){return this._timeFromRequest}get timeOfResponse(){return this._timeReceivedResponse}get latencyTotal(){return this._timeReceivedResponse-this._timeFromRequest}get latencyAtPeer(){return this._timeAtSender-this._timeFromRequest}};Me.NAME="Foundation::PingResponse",Me.VERSION=2;let We=Me;class tt extends fe{constructor(e){if(super(e),typeof this.raw.body.value!="string")throw new Error("Incorrect response type in HighLevelUpdate");try{this.responseData=JSON.parse(this.raw.body.value)}catch(t){throw new Error(`Could not parse HighLevelUpdate: ${t.message}`)}}get data(){return this.responseData}}const rt=8;var f=(r=>(r[r.TRACE=10]="TRACE",r[r.DEBUG=20]="DEBUG",r[r.INFO=30]="INFO",r[r.WARN=40]="WARN",r[r.ERROR=50]="ERROR",r[r.FATAL=60]="FATAL",r[r.SILENT=100]="SILENT",r))(f||{});const le=class le{constructor(e=""){this.defaultLevel=40,this.noop=()=>null,this.name=e,this.setDefaultLevelFromLocalStorage(),Object.assign(le.loggers,{[e]:this})}getName(){return this.name}setLevel(e){this.level=e}getLevel(){return typeof this.level=="number"&&isFinite(this.level)&&Math.floor(this.level)===this.level?this.level:this.defaultLevel}shouldLog(e){switch(this.getLevel()){case 100:return!1;case 60:return e==="fatal";case 50:return e==="fatal"||e==="error";case 40:return e==="fatal"||e==="error"||e==="warn";case 30:return e==="fatal"||e==="error"||e==="warn"||e==="info";case 20:return e==="fatal"||e==="error"||e==="warn"||e==="info"||e==="debug";default:return!0}}setDefaultLevelFromLocalStorage(){let e;try{if(!(typeof localStorage=="object"))return;const n=localStorage.getItem("loglevel");if(!n)return;e=n}catch{return}e&&this.setLevel(le.getLogLevel(e))}static getLogLevel(e){const t=e.toLowerCase();switch(t){case"silent":return 100;case"fatal":return 60;case"error":return 50;case"warn":return 40;case"info":return 30;case"debug":return 20;case"trace":return 10;default:throw new Error(`Invalid log level: ${t}`)}}static getLogger(e,t){if(Object.prototype.hasOwnProperty.call(le.loggers,e))return le.loggers[e];const n=new t(e);return le.loggers[e]=n,n}};le.loggers={};let ce=le;class Pr{static getLogLevel(e){const t=e.toLowerCase();switch(t){case"silent":return f.SILENT;case"fatal":return f.FATAL;case"error":return f.ERROR;case"warn":return f.WARN;case"info":return f.INFO;case"debug":return f.DEBUG;case"trace":return f.TRACE;default:throw new Error(`Invalid log level: ${t}`)}}}class nt extends ce{constructor(){super(...arguments),this.trace=this.getLogMethod("trace"),this.debug=this.getLogMethod("debug"),this.info=this.getLogMethod("info"),this.warn=this.getLogMethod("warn"),this.error=this.getLogMethod("error"),this.fatal=this.getLogMethod("fatal")}setLevel(e){this.level=e,this.trace=this.getLogMethod("trace"),this.debug=this.getLogMethod("debug"),this.info=this.getLogMethod("info"),this.warn=this.getLogMethod("warn"),this.error=this.getLogMethod("error"),this.fatal=this.getLogMethod("fatal")}getLogMethod(e){if(this.shouldLog(e)){const t=e==="debug"||e==="fatal"?"log":e,n=this.name?`${this.name}: [${e.toUpperCase()}] `:`-----> [${e.toUpperCase()}] `;return Function.prototype.bind.call(console[t],console,n)}return this.noop}static getLogger(e=""){return super.getLogger(e,nt)}}const xr={silent:0,fatal:1,error:2,warn:3,info:4,debug:5,trace:6};class Fr extends ce{constructor(e,t=""){super(t),this.name=t,this.logger=e,this.trace=Function.prototype.bind.call(e.trace,e),this.debug=Function.prototype.bind.call(e.debug,e),this.info=Function.prototype.bind.call(e.info,e),this.warn=Function.prototype.bind.call(e.warn,e),this.error=Function.prototype.bind.call(e.error,e),this.fatal=Function.prototype.bind.call(e.error,e)}setLevel(e){this.level=e,this.logger&&(this.logger.level=f[e].toLowerCase())}static getLogger(e=""){return Object.prototype.hasOwnProperty.call(ce.loggers,e)?ce.loggers[e]:null}}class ot extends ce{constructor(){super(...arguments),this.trace=this.noop,this.debug=this.noop,this.info=this.noop,this.warn=this.noop,this.error=this.noop}static getLogger(e=""){return super.getLogger(e,ot)}}const $r=()=>j(e=>class extends e{async requestAuthenticationToken(t=30,n=0,o=0,s=this.defaultTimeoutInMs){const c={message:new Le(t,n,o,s).getPtlMessage(),callbackType:"job",callbackId:""};await this.hooks.callHook("frontgateConnection:sendMessage",c);const a=new Promise((u,h)=>{this.hooks.hookOnce(`frontgateConnection:response:${c.callbackId}`,p=>{if(!p.Message.includes("AuthenticationTokenResponse")){h(JSON.stringify(p));return}const m=new Wt(p);u({token:m.getToken(),expiry:m.getExpiry()})})}),l=`Request timeout reached (${s} ms) for ${c.message.Message}`;return Y(s,l,a)}async requestAuthenticationTokenForCookieTokenAuthentication(t=30,n=0,o=0,s=this.defaultTimeoutInMs){const i=await this.requestAuthenticationToken(t,n,o,s);return new $t(i.token)}},{featureName:"AuthTokenRequest",featureGroups:["Misc"]}),Ur=r=>j(t=>class extends t{async requestEndpoint(n,o,s,i,c=this.defaultTimeoutInMs){const a=new ke(n,o,s,{...i,allowChunkedResponse:!r?.disableChunkedResponse});a.header.setTimeout(c),r?.allowPermissionDeniedResponse&&a.header.setFlag("permission_denied_response");const l={message:a.getPtlMessage(),callbackType:"job",callbackId:""};await this.hooks.callHook("frontgateConnection:sendMessage",l);const u=new Promise((p,m)=>{const M=[],T=()=>{this.hooks.hookOnce(`frontgateConnection:response:${l.callbackId}`,_=>{try{if(!_.Message.includes("HighLevelResponse")){m(JSON.stringify(_));return}if(this.#e(_))M.push({body:_.body?.value??"",processingTime:_.header?.processingTime??0}),T();else{M.push({body:_.body?.value??"",processingTime:_.header?.processingTime??0});const d=new Jt({..._,body:{value:M.map(v=>v.body).join("")},header:{..._.header,processingTime:M.reduce((v,g)=>v+g.processingTime,0)}});p({response:d,data:d.data})}}catch(d){m(d)}})};T()}),h=`Request timeout reached (${c} ms) for ${l.message.Message}`;return Y(c,h,u)}#e(n){return((n.header?.flags??0)&rt)===rt}},{featureName:"EndpointRequest",featureGroups:["Misc"]});var de=null;typeof WebSocket<"u"?de=WebSocket:typeof MozWebSocket<"u"?de=MozWebSocket:typeof global<"u"?de=global.WebSocket||global.MozWebSocket:typeof window<"u"?de=window.WebSocket||window.MozWebSocket:typeof self<"u"&&(de=self.WebSocket||self.MozWebSocket);const st=r=>j(t=>class extends t{#e;#t;#r="disconnected";#n;#o=0;#s;#i;get#a(){return this.#e&&this.#e.readyState<2?this.#r:"disconnected"}#c;#u=[];set conf(n){const o=this.#b(n);this.#c=o.messageBufferSize,this.#t=o}constructor(...n){super(...n),this.#s=oe,this.#i=Ut,r&&(this.conf=r),this.hooks.hook("frontgateConnection:setIdApp",o=>{this.#s=o}),this.hooks.hook("frontgateConnection:setIdUser",o=>{this.#i=o}),this.hooks.hook("frontgateConnection:sendMessage",o=>{if(o.callbackType==="job"){const s=this.#p(o.message);o.callbackId=`${s}`,this.#f(o.message)}if(this.#a==="connected"&&o.callbackType==="response")this.#h(o.message);else if(this.#a==="authenticated")this.#h(o.message);else{if(this.#u.length>=this.#c)throw new Error("Message buffer is full");this.#u.push(o)}}),this.hooks.hook("frontgateConnection:authenticated",()=>{if(!this.#t)throw new Error("No connection configuration set");for(this.log(f.DEBUG,"Draining message buffer");this.#u.length>0;){const o=this.#u.shift();o&&(this.#f(o.message),this.#h(o.message))}this.#n=setInterval(()=>{this.log(f.DEBUG,"Sending keepalive"),this.hooks.callHook("frontgateConnection:sendMessage",{message:this.#g(),callbackType:"response",callbackId:"KeepAliveMessage"})},this.#t.maximumIdleIntervalInS/2*1e3)}),this.hooks.hook("reconnect:attempt",async()=>{clearInterval(this.#n),this.log(f.DEBUG,"Reconnecting"),await this.hooks.callHook("frontgateConnection:reset");try{await this.connect(),await this.hooks.callHook("reconnect:success")}catch(o){this.log(f.ERROR,"Reconnect failed",o),await this.hooks.callHook("reconnect:failed",o)}})}async connect(){if(!this.#t)throw new Error("No connection configuration set");if(this.#a!=="disconnected")throw new Error("Client is already connected or is connecting right now");const{host:n,port:o,tls:s,pathPrefix:i}=this.#t;this.#r="connecting";const a=`${s?"wss":"ws"}://${n}:${o}${i??""}/ws`,l={encoding:"jsjson-v2"};await this.hooks.callHook("frontgateConnection:afterSetEncoding",l);const[u,h]=l.encoding.split("-"),m=[`${h?`${h}.`:""}ws-${u}.mdgms.com`],M={url:a,subProtocols:m};try{await this.hooks.callHook("frontgateConnection:beforeConnect",M)}catch(d){throw this.#r="disconnected",d}this.log(f.DEBUG,`Connecting to ${M.url} with subprotocols ${M.subProtocols}`);const T=new Promise((d,v)=>{if(!this.#t)throw new Error("No connection configuration set");this.#t.wsClientOptions&&typeof window>"u"?this.#e=new de(M.url,M.subProtocols,this.#t.wsClientOptions):this.#e=new de(M.url,M.subProtocols),this.#e.binaryType="arraybuffer";let g;this.#e.onopen=()=>{this.#r="connected",this.log(f.DEBUG,"Connected"),this.hooks.callHook("frontgateConnection:connected",this.#t).catch(v),g=this.hooks.hookOnce("frontgateConnection:authenticated",()=>{this.#r="authenticated",this.log(f.DEBUG,"Authenticated"),d()})},this.#e.onclose=w=>{g?.(),this.log(f.DEBUG,"Disconnected",w),this.#r==="connecting"||this.#r==="connected"?v(JSON.stringify(w)):this.hooks.callHook("frontgateConnection:disconnected",w),clearInterval(this.#n),this.#r="disconnected"},this.#e.onerror=w=>{g?.(),this.log(f.ERROR,"Error:",w),this.hooks.callHook("frontgateConnection:error",w),(this.#r==="connecting"||this.#r==="connected")&&v(new Error("Websocket error")),clearInterval(this.#n),this.#r="disconnected"},this.#e.onmessage=w=>{const{data:y}=w;this.log(f.DEBUG,"Received data:",y);const I={msg:y};this.hooks.callHook("frontgateConnection:afterReceiveMessage",I).then(()=>{this.log(f.DEBUG,"Received message",I.msg);const N=I.msg.toString("utf-8"),E=JSON.parse(N);if(this.hooks.callHook("frontgateConnection:message",E),E.Message==="Foundation::DisconnectionMessage"){this.#e?.close(),this.hooks.callHook("frontgateConnection:disconnected",E);return}this.#l(E)})}}),_=`Timeout reached (${this.defaultTimeoutInMs} ms) for connection to ${a}`;return Y(this.defaultTimeoutInMs,_,T)}async disconnect(){return new Promise(n=>{this.#h(this.#d()),this.hooks.hookOnce("frontgateConnection:disconnected",()=>{this.#e?.close(),n()})})}#d(){return{Message:"Foundation::DisconnectionMessage",Version:3,reason:{value:64},details:"client shutdown"}}#g(){return{Message:"KeepAliveMessage",Version:2}}async#h(n){await this.hooks.callHook("frontgateConnection:beforeSerializeMessage",n);const o={msg:JSON.stringify(n)};await this.hooks.callHook("frontgateConnection:beforeSendMessage",o),this.log(f.DEBUG,"Sending message:",n),this.log(f.TRACE,"Sending data:",o.msg);try{this.#e?.send(o.msg)}catch(s){const i=this.#v(s,n);this.#l(i.msg)}}#l(n){if(typeof n.header?.id_job<"u"){this.hooks.callHook(`frontgateConnection:response:${n.header.id_job}`,n);return}if(typeof n.header?.id_service<"u"&&typeof n.id_notation<"u"){this.hooks.callHook(`frontgateConnection:response:${n.header.id_service}-${n.id_notation}`,n);return}if(typeof n.id_job<"u"){this.hooks.callHook(`frontgateConnection:response:${n.id_job}`,n);return}typeof n.Message=="string"&&this.hooks.callHook(`frontgateConnection:response:${n.Message.replace("Foundation::","")}`,n)}#p(n){this.#o+=1;const o=this.#o;return n.header={...n.header,id_job:o},this.#o}#f(n){n.header||(n.header={authentication_identifiers:{id_application:void 0,id_user:void 0}}),n.header.authentication_identifiers||(n.header={...n.header,authentication_identifiers:{id_application:void 0,id_user:void 0}}),n.header.authentication_identifiers.id_application||=this.#s,n.header.authentication_identifiers.id_user||=this.#i}#v(n,o){return new z({Message:"Foundation::ErrorResponse",Version:1,id_job:o.header?.id_job,reason:8,details:n})}#b(n){const o=n.maximumIdleIntervalInS??60,s=n.maximumIdleInterval??o*1e6;return{...n,payloadContent:n.payloadContent??"foundation",maximumIdleIntervalInS:o,maximumIdleInterval:s,tls:n.tls??!0,messageBufferSize:n.messageBufferSize??512}}isConnected(){return this.#a==="authenticated"}isDisconnected(){return this.#r!=="authenticated"}isReadyToConnect(){return this.#a==="disconnected"}},{featureName:"WSConnection",disabledFeatureGroups:["Connection"]}),Dr=(r,e)=>(e&&r.setLevel(e),j(n=>class extends n{constructor(...o){super(...o),this.logger=r}},{featureName:"Logger",featureGroups:["Misc"]}));var S=Uint8Array,L=Uint16Array,it=Int32Array,Je=new S([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ze=new S([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),at=new S([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Kt=function(r,e){for(var t=new L(31),n=0;n<31;++n)t[n]=e+=1<<r[n-1];for(var o=new it(t[30]),n=1;n<30;++n)for(var s=t[n];s<t[n+1];++s)o[s]=s-t[n]<<5|n;return{b:t,r:o}},Yt=Kt(Je,2),Qt=Yt.b,ct=Yt.r;Qt[28]=258,ct[258]=28;for(var Xt=Kt(ze,0),jr=Xt.b,Zt=Xt.r,ut=new L(32768),O=0;O<32768;++O){var ue=(O&43690)>>1|(O&21845)<<1;ue=(ue&52428)>>2|(ue&13107)<<2,ue=(ue&61680)>>4|(ue&3855)<<4,ut[O]=((ue&65280)>>8|(ue&255)<<8)>>1}for(var te=(function(r,e,t){for(var n=r.length,o=0,s=new L(e);o<n;++o)r[o]&&++s[r[o]-1];var i=new L(e);for(o=1;o<e;++o)i[o]=i[o-1]+s[o-1]<<1;var c;if(t){c=new L(1<<e);var a=15-e;for(o=0;o<n;++o)if(r[o])for(var l=o<<4|r[o],u=e-r[o],h=i[r[o]-1]++<<u,p=h|(1<<u)-1;h<=p;++h)c[ut[h]>>a]=l}else for(c=new L(n),o=0;o<n;++o)r[o]&&(c[o]=ut[i[r[o]-1]++]>>15-r[o]);return c}),he=new S(288),O=0;O<144;++O)he[O]=8;for(var O=144;O<256;++O)he[O]=9;for(var O=256;O<280;++O)he[O]=7;for(var O=280;O<288;++O)he[O]=8;for(var Re=new S(32),O=0;O<32;++O)Re[O]=5;var Hr=te(he,9,0),Gr=te(he,9,1),qr=te(Re,5,0),Lr=te(Re,5,1),ht=function(r){for(var e=r[0],t=1;t<r.length;++t)r[t]>e&&(e=r[t]);return e},Q=function(r,e,t){var n=e/8|0;return(r[n]|r[n+1]<<8)>>(e&7)&t},lt=function(r,e){var t=e/8|0;return(r[t]|r[t+1]<<8|r[t+2]<<16)>>(e&7)},ft=function(r){return(r+7)/8|0},ge=function(r,e,t){return(e==null||e<0)&&(e=0),(t==null||t>r.length)&&(t=r.length),new S(r.subarray(e,t))},Br=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],D=function(r,e,t){var n=new Error(e||Br[r]);if(n.code=r,Error.captureStackTrace&&Error.captureStackTrace(n,D),!t)throw n;return n},Vr=function(r,e,t,n){var o=r.length,s=0;if(!o||e.f&&!e.l)return t||new S(0);var i=!t,c=i||e.i!=2,a=e.i;i&&(t=new S(o*3));var l=function(je){var He=t.length;if(je>He){var Ie=new S(Math.max(He*2,je));Ie.set(t),t=Ie}},u=e.f||0,h=e.p||0,p=e.b||0,m=e.l,M=e.d,T=e.m,_=e.n,d=o*8;do{if(!m){u=Q(r,h,1);var v=Q(r,h+1,3);if(h+=3,v)if(v==1)m=Gr,M=Lr,T=9,_=5;else if(v==2){var I=Q(r,h,31)+257,N=Q(r,h+10,15)+4,E=I+Q(r,h+5,31)+1;h+=14;for(var k=new S(E),C=new S(19),A=0;A<N;++A)C[at[A]]=Q(r,h+A*3,7);h+=N*3;for(var P=ht(C),$=(1<<P)-1,R=te(C,P,1),A=0;A<E;){var H=R[Q(r,h,$)];h+=H&15;var g=H>>4;if(g<16)k[A++]=g;else{var U=0,x=0;for(g==16?(x=3+Q(r,h,3),h+=2,U=k[A-1]):g==17?(x=3+Q(r,h,7),h+=3):g==18&&(x=11+Q(r,h,127),h+=7);x--;)k[A++]=U}}var q=k.subarray(0,I),G=k.subarray(I);T=ht(q),_=ht(G),m=te(q,T,1),M=te(G,_,1)}else D(1);else{var g=ft(h)+4,w=r[g-4]|r[g-3]<<8,y=g+w;if(y>o){a&&D(0);break}c&&l(p+w),t.set(r.subarray(g,y),p),e.b=p+=w,e.p=h=y*8,e.f=u;continue}if(h>d){a&&D(0);break}}c&&l(p+131072);for(var De=(1<<T)-1,K=(1<<_)-1,ie=h;;ie=h){var U=m[lt(r,h)&De],W=U>>4;if(h+=U&15,h>d){a&&D(0);break}if(U||D(2),W<256)t[p++]=W;else if(W==256){ie=h,m=null;break}else{var J=W-254;if(W>264){var A=W-257,F=Je[A];J=Q(r,h,(1<<F)-1)+Qt[A],h+=F}var ne=M[lt(r,h)&K],Ee=ne>>4;ne||D(3),h+=ne&15;var G=jr[Ee];if(Ee>3){var F=ze[Ee];G+=lt(r,h)&(1<<F)-1,h+=F}if(h>d){a&&D(0);break}c&&l(p+131072);var Te=p+J;if(p<G){var Xe=s-G,Ze=Math.min(G,Te);for(Xe+p<0&&D(3);p<Ze;++p)t[p]=n[Xe+p]}for(;p<Te;++p)t[p]=t[p-G]}}e.l=m,e.p=ie,e.b=p,e.f=u,m&&(u=1,e.m=T,e.d=M,e.n=_)}while(!u);return p!=t.length&&i?ge(t,0,p):t.subarray(0,p)},se=function(r,e,t){t<<=e&7;var n=e/8|0;r[n]|=t,r[n+1]|=t>>8},Oe=function(r,e,t){t<<=e&7;var n=e/8|0;r[n]|=t,r[n+1]|=t>>8,r[n+2]|=t>>16},dt=function(r,e){for(var t=[],n=0;n<r.length;++n)r[n]&&t.push({s:n,f:r[n]});var o=t.length,s=t.slice();if(!o)return{t:nr,l:0};if(o==1){var i=new S(t[0].s+1);return i[t[0].s]=1,{t:i,l:1}}t.sort(function(y,I){return y.f-I.f}),t.push({s:-1,f:25001});var c=t[0],a=t[1],l=0,u=1,h=2;for(t[0]={s:-1,f:c.f+a.f,l:c,r:a};u!=o-1;)c=t[t[l].f<t[h].f?l++:h++],a=t[l!=u&&t[l].f<t[h].f?l++:h++],t[u++]={s:-1,f:c.f+a.f,l:c,r:a};for(var p=s[0].s,n=1;n<o;++n)s[n].s>p&&(p=s[n].s);var m=new L(p+1),M=gt(t[u-1],m,0);if(M>e){var n=0,T=0,_=M-e,d=1<<_;for(s.sort(function(I,N){return m[N.s]-m[I.s]||I.f-N.f});n<o;++n){var v=s[n].s;if(m[v]>e)T+=d-(1<<M-m[v]),m[v]=e;else break}for(T>>=_;T>0;){var g=s[n].s;m[g]<e?T-=1<<e-m[g]++-1:++n}for(;n>=0&&T;--n){var w=s[n].s;m[w]==e&&(--m[w],++T)}M=e}return{t:new S(m),l:M}},gt=function(r,e,t){return r.s==-1?Math.max(gt(r.l,e,t+1),gt(r.r,e,t+1)):e[r.s]=t},er=function(r){for(var e=r.length;e&&!r[--e];);for(var t=new L(++e),n=0,o=r[0],s=1,i=function(a){t[n++]=a},c=1;c<=e;++c)if(r[c]==o&&c!=e)++s;else{if(!o&&s>2){for(;s>138;s-=138)i(32754);s>2&&(i(s>10?s-11<<5|28690:s-3<<5|12305),s=0)}else if(s>3){for(i(o),--s;s>6;s-=6)i(8304);s>2&&(i(s-3<<5|8208),s=0)}for(;s--;)i(o);s=1,o=r[c]}return{c:t.subarray(0,n),n:e}},Ne=function(r,e){for(var t=0,n=0;n<e.length;++n)t+=r[n]*e[n];return t},tr=function(r,e,t){var n=t.length,o=ft(e+2);r[o]=n&255,r[o+1]=n>>8,r[o+2]=r[o]^255,r[o+3]=r[o+1]^255;for(var s=0;s<n;++s)r[o+s+4]=t[s];return(o+4+n)*8},rr=function(r,e,t,n,o,s,i,c,a,l,u){se(e,u++,t),++o[256];for(var h=dt(o,15),p=h.t,m=h.l,M=dt(s,15),T=M.t,_=M.l,d=er(p),v=d.c,g=d.n,w=er(T),y=w.c,I=w.n,N=new L(19),E=0;E<v.length;++E)++N[v[E]&31];for(var E=0;E<y.length;++E)++N[y[E]&31];for(var k=dt(N,7),C=k.t,A=k.l,P=19;P>4&&!C[at[P-1]];--P);var $=l+5<<3,R=Ne(o,he)+Ne(s,Re)+i,H=Ne(o,p)+Ne(s,T)+i+14+3*P+Ne(N,C)+2*N[16]+3*N[17]+7*N[18];if(a>=0&&$<=R&&$<=H)return tr(e,u,r.subarray(a,a+l));var U,x,q,G;if(se(e,u,1+(H<R)),u+=2,H<R){U=te(p,m,0),x=p,q=te(T,_,0),G=T;var De=te(C,A,0);se(e,u,g-257),se(e,u+5,I-1),se(e,u+10,P-4),u+=14;for(var E=0;E<P;++E)se(e,u+3*E,C[at[E]]);u+=3*P;for(var K=[v,y],ie=0;ie<2;++ie)for(var W=K[ie],E=0;E<W.length;++E){var J=W[E]&31;se(e,u,De[J]),u+=C[J],J>15&&(se(e,u,W[E]>>5&127),u+=W[E]>>12)}}else U=Hr,x=he,q=qr,G=Re;for(var E=0;E<c;++E){var F=n[E];if(F>255){var J=F>>18&31;Oe(e,u,U[J+257]),u+=x[J+257],J>7&&(se(e,u,F>>23&31),u+=Je[J]);var ne=F&31;Oe(e,u,q[ne]),u+=G[ne],ne>3&&(Oe(e,u,F>>5&8191),u+=ze[ne])}else Oe(e,u,U[F]),u+=x[F]}return Oe(e,u,U[256]),u+x[256]},Wr=new it([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),nr=new S(0),Jr=function(r,e,t,n,o,s){var i=s.z||r.length,c=new S(n+i+5*(1+Math.ceil(i/7e3))+o),a=c.subarray(n,c.length-o),l=s.l,u=(s.r||0)&7;if(e){u&&(a[0]=s.r>>3);for(var h=Wr[e-1],p=h>>13,m=h&8191,M=(1<<t)-1,T=s.p||new L(32768),_=s.h||new L(M+1),d=Math.ceil(t/3),v=2*d,g=function(Pt){return(r[Pt]^r[Pt+1]<<d^r[Pt+2]<<v)&M},w=new it(25e3),y=new L(288),I=new L(32),N=0,E=0,k=s.i||0,C=0,A=s.w||0,P=0;k+2<i;++k){var $=g(k),R=k&32767,H=_[$];if(T[R]=H,_[$]=R,A<=k){var U=i-k;if((N>7e3||C>24576)&&(U>423||!l)){u=rr(r,a,0,w,y,I,E,C,P,k-P,u),C=N=E=0,P=k;for(var x=0;x<286;++x)y[x]=0;for(var x=0;x<30;++x)I[x]=0}var q=2,G=0,De=m,K=R-H&32767;if(U>2&&$==g(k-K))for(var ie=Math.min(p,U)-1,W=Math.min(32767,k),J=Math.min(258,U);K<=W&&--De&&R!=H;){if(r[k+q]==r[k+q-K]){for(var F=0;F<J&&r[k+F]==r[k+F-K];++F);if(F>q){if(q=F,G=K,F>ie)break;for(var ne=Math.min(K,F-2),Ee=0,x=0;x<ne;++x){var Te=k-K+x&32767,Xe=T[Te],Ze=Te-Xe&32767;Ze>Ee&&(Ee=Ze,H=Te)}}}R=H,H=T[R],K+=R-H&32767}if(G){w[C++]=268435456|ct[q]<<18|Zt[G];var je=ct[q]&31,He=Zt[G]&31;E+=Je[je]+ze[He],++y[257+je],++I[He],A=k+q,++N}else w[C++]=r[k],++y[r[k]]}}for(k=Math.max(k,A);k<i;++k)w[C++]=r[k],++y[r[k]];u=rr(r,a,l,w,y,I,E,C,P,k-P,u),l||(s.r=u&7|a[u/8|0]<<3,u-=7,s.h=_,s.p=T,s.i=k,s.w=A)}else{for(var k=s.w||0;k<i+l;k+=65535){var Ie=k+65535;Ie>=i&&(a[u/8|0]=l,Ie=i),u=tr(a,u+1,r.subarray(k,Ie))}s.i=i}return ge(c,0,n+ft(u)+o)},or=function(){var r=1,e=0;return{p:function(t){for(var n=r,o=e,s=t.length|0,i=0;i!=s;){for(var c=Math.min(i+2655,s);i<c;++i)o+=n+=t[i];n=(n&65535)+15*(n>>16),o=(o&65535)+15*(o>>16)}r=n,e=o},d:function(){return r%=65521,e%=65521,(r&255)<<24|(r&65280)<<8|(e&255)<<8|e>>8}}},sr=function(r,e,t,n,o){if(!o&&(o={l:1},e.dictionary)){var s=e.dictionary.subarray(-32768),i=new S(s.length+r.length);i.set(s),i.set(r,s.length),r=i,o.w=s.length}return Jr(r,e.level==null?6:e.level,e.mem==null?o.l?Math.ceil(Math.max(8,Math.min(13,Math.log(r.length)))*1.5):20:12+e.mem,t,n,o)},ir=function(r,e,t){for(;t;++e)r[e]=t,t>>>=8},zr=function(r,e){var t=e.level,n=t==0?0:t<6?1:t==9?3:2;if(r[0]=120,r[1]=n<<6|(e.dictionary&&32),r[1]|=31-(r[0]<<8|r[1])%31,e.dictionary){var o=or();o.p(e.dictionary),ir(r,2,o.d())}},Kr=function(r,e){return((r[0]&15)!=8||r[0]>>4>7||(r[0]<<8|r[1])%31)&&D(6,"invalid zlib data"),(r[1]>>5&1)==+!e&&D(6,"invalid zlib data: "+(r[1]&32?"need":"unexpected")+" dictionary"),(r[1]>>3&4)+2},pt=(function(){function r(e,t){if(typeof e=="function"&&(t=e,e={}),this.ondata=t,this.o=e||{},this.s={l:0,i:32768,w:32768,z:32768},this.b=new S(98304),this.o.dictionary){var n=this.o.dictionary.subarray(-32768);this.b.set(n,32768-n.length),this.s.i=32768-n.length}}return r.prototype.p=function(e,t){this.ondata(sr(e,this.o,0,0,this.s),t)},r.prototype.push=function(e,t){this.ondata||D(5),this.s.l&&D(4);var n=e.length+this.s.z;if(n>this.b.length){if(n>2*this.b.length-32768){var o=new S(n&-32768);o.set(this.b.subarray(0,this.s.z)),this.b=o}var s=this.b.length-this.s.z;this.b.set(e.subarray(0,s),this.s.z),this.s.z=this.b.length,this.p(this.b,!1),this.b.set(this.b.subarray(-32768)),this.b.set(e.subarray(s),32768),this.s.z=e.length-s+32768,this.s.i=32766,this.s.w=32768}else this.b.set(e,this.s.z),this.s.z+=e.length;this.s.l=t&1,(this.s.z>this.s.w+8191||t)&&(this.p(this.b,t||!1),this.s.w=this.s.i,this.s.i-=2)},r.prototype.flush=function(){this.ondata||D(5),this.s.l&&D(4),this.p(this.b,!1),this.s.w=this.s.i,this.s.i-=2},r})(),vt=(function(){function r(e,t){typeof e=="function"&&(t=e,e={}),this.ondata=t;var n=e&&e.dictionary&&e.dictionary.subarray(-32768);this.s={i:0,b:n?n.length:0},this.o=new S(32768),this.p=new S(0),n&&this.o.set(n)}return r.prototype.e=function(e){if(this.ondata||D(5),this.d&&D(4),!this.p.length)this.p=e;else if(e.length){var t=new S(this.p.length+e.length);t.set(this.p),t.set(e,this.p.length),this.p=t}},r.prototype.c=function(e){this.s.i=+(this.d=e||!1);var t=this.s.b,n=Vr(this.p,this.s,this.o);this.ondata(ge(n,t,this.s.b),this.d),this.o=ge(n,this.s.b-32768),this.s.b=this.o.length,this.p=ge(this.p,this.s.p/8|0),this.s.p&=7},r.prototype.push=function(e,t){this.e(e),this.c(t)},r})(),Yr=(function(){function r(e,t){this.c=or(),this.v=1,pt.call(this,e,t)}return r.prototype.push=function(e,t){this.c.p(e),pt.prototype.push.call(this,e,t)},r.prototype.p=function(e,t){var n=sr(e,this.o,this.v&&(this.o.dictionary?6:2),t&&4,this.s);this.v&&(zr(n,this.o),this.v=0),t&&ir(n,n.length-4,this.c.d()),this.ondata(n,t)},r.prototype.flush=function(){pt.prototype.flush.call(this)},r})(),Qr=(function(){function r(e,t){vt.call(this,e,t),this.v=e&&e.dictionary?2:1}return r.prototype.push=function(e,t){if(vt.prototype.e.call(this,e),this.v){if(this.p.length<6&&!t)return;this.p=this.p.subarray(Kr(this.p,this.v-1)),this.v=0}t&&(this.p.length<4&&D(6,"invalid zlib data"),this.p=this.p.subarray(0,-4)),vt.prototype.c.call(this,t)},r})(),ar=typeof TextEncoder<"u"&&new TextEncoder,bt=typeof TextDecoder<"u"&&new TextDecoder,Xr=0;try{bt.decode(nr,{stream:!0}),Xr=1}catch{}var Zr=function(r){for(var e="",t=0;;){var n=r[t++],o=(n>127)+(n>223)+(n>239);if(t+o>r.length)return{s:e,r:ge(r,t-1)};o?o==3?(n=((n&15)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,e+=String.fromCharCode(55296|n>>10,56320|n&1023)):o&1?e+=String.fromCharCode((n&31)<<6|r[t++]&63):e+=String.fromCharCode((n&15)<<12|(r[t++]&63)<<6|r[t++]&63):e+=String.fromCharCode(n)}};function en(r,e){var t;if(ar)return ar.encode(r);for(var n=r.length,o=new S(r.length+(r.length>>1)),s=0,i=function(l){o[s++]=l},t=0;t<n;++t){if(s+5>o.length){var c=new S(s+8+(n-t<<1));c.set(o),o=c}var a=r.charCodeAt(t);a<128||e?i(a):a<2048?(i(192|a>>6),i(128|a&63)):a>55295&&a<57344?(a=65536+(a&1047552)|r.charCodeAt(++t)&1023,i(240|a>>18),i(128|a>>12&63),i(128|a>>6&63),i(128|a&63)):(i(224|a>>12),i(128|a>>6&63),i(128|a&63))}return ge(o,0,s)}function tn(r,e){var t;if(bt)return bt.decode(r);var n=Zr(r),o=n.s,t=n.r;return t.length&&D(8),o}const rn=r=>{if(r.length===1)return r[0];const e=new Uint8Array(r.reduce((t,n)=>t+n.length,0));for(let t=0,n=0;t<r.length;++t)e.set(r[t],n),n+=r[t].length;return e};class cr{constructor(){this.reset()}reset(){this.compressor=null,this.decompressor=null}compress(e){this.compressor||(this.compressor=new Yr({mem:4}));const t=[];return this.compressor.ondata=n=>{t.push(n)},this.compressor.push(en(e)),this.compressor.flush(),rn(t)}decompress(e){this.decompressor||(this.decompressor=new Qr);let t;this.decompressor.ondata=n=>{t=n};try{if(this.decompressor.push(e),t===void 0)throw new Error("invalid block type")}catch(n){throw new Error(`Decompression error: ${n.message}, length: ${e.length}, data: [${e.toString()}]`)}return tn(t)}}const nn=()=>j(e=>class extends e{#e;constructor(...t){super(...t),this.#e=new cr,this.hooks.hook("frontgateConnection:reset",()=>{this.#e.reset()}),this.hooks.hook("frontgateConnection:afterSetEncoding",n=>{n.encoding="jsjsonc-v2"}),this.hooks.hook("frontgateConnection:beforeSendMessage",n=>{const o=this.#e.compress(n.msg);n.msg=o}),this.hooks.hook("frontgateConnection:afterReceiveMessage",n=>{const o=this.#e.decompress(new Uint8Array(n.msg));n.msg=o})}},{featureName:"MessageCompressor",featureGroups:["Compression"]}),on=()=>j(e=>class extends e{async request(t,n=this.defaultTimeoutInMs){t.header.setTimeout(n);const o={message:t.getPtlMessage(),callbackType:"job",callbackId:""};await this.hooks.callHook("frontgateConnection:sendMessage",o);const s=new Promise(c=>{this.hooks.hookOnce(`frontgateConnection:response:${o.callbackId}`,a=>{const l=new fe(a);c(l)})}),i=`Request timeout reached (${n} ms) for ${o.message.Message}`;return Y(n,i,s)}},{featureName:"Request",featureGroups:["Misc"]}),sn=r=>j(t=>{const n={...r};return class extends t{#e=new Map;#t=new Map;#r=new Map;async observeEndpoint(o,s,i,c){const a=`${o}:${s}:${JSON.stringify(i)}:${JSON.stringify(c??{})}`;if(this.#r.has(a)){const d=this.#r.get(a);this.log(f.INFO,`Catching inflight subscription for ${a}`);const v=this.#t.get(a)??0;return this.#t.set(a,v+1),d}const l=n.timeout??this.defaultTimeoutInMs,u=n.subscriptionResubscribeTimeout??1e3;if(this.#e.has(a)){const d=this.#e.get(a),v=this.#t.get(a)??0;if(d)return this.#t.set(a,v+1),this.log(f.INFO,`Reusing existing subscription for ${a}`),d}this.log(f.INFO,`Creating new subscription for ${a}`);const h=new ke(o,s,i,{...c,subscribe:!0});h.header.setTimeout(l);const p={message:h.getPtlMessage(),callbackType:"job",callbackId:""};let m=!1;const M=new Promise((d,v)=>{this.hooks.callHook("frontgateConnection:sendMessage",p).then(()=>{this.hooks.hookOnce(`frontgateConnection:response:${p.callbackId}`,g=>{if(!g.Message.includes("HighLevelResponse")){this.log(f.ERROR,`Unexpected response: ${g.Message}`),v(new z(JSON.stringify(g)));return}let w;try{w=JSON.parse(g.body.value)}catch(C){this.log(f.ERROR,`Failed to parse response: ${g.body.value}`),this.log(f.ERROR,C),v(C);return}const y=new ur(g.header.id_job,w);let I=this.hooks.hook(`frontgateConnection:response:${p.callbackId}`,C=>{if(!C.Message.includes("HighLevelUpdate")){if(C.Message.includes("SubscriptionLoss")){this.log(f.DEBUG,`Received: ${C.Message}`),setTimeout(()=>{N()},Lt(u)),I();return}this.log(f.ERROR,`Unexpected response: ${g.Message}`),y.pushError(new z(JSON.stringify(C))),I();return}let A;try{A=new tt(C)}catch(P){this.log(f.ERROR,`Failed to parse response: ${C.body.value}`),y.pushError(P);return}y.pushPatchData(A.data)});const N=async()=>{I(),this.log(f.INFO,`Resubscribing to ${a} due to reconnect`),await this.hooks.callHook("frontgateConnection:sendMessage",p);const C=new Promise((A,P)=>{this.hooks.hookOnce(`frontgateConnection:response:${p.callbackId}`,$=>{if(!$.Message.includes("HighLevelResponse")){const R=new z($);this.log(f.ERROR,`Unexpected response: ${$.Message}`),I(),P(R);return}if(this.log(f.INFO,`Resubscribed to ${a} with ${$.header.id_job}`),y.idJob=$.header.id_job,m){this.log(f.WARN,`Zombie subscription detected for ${a}. Initiating unsubscribe.`),y.unsubscribe(),A();return}try{y.pushData(JSON.parse($.body.value))}catch(R){this.log(f.ERROR,`Failed to parse response: ${$.body.value}`),this.log(f.ERROR,R),P(R);return}I=this.hooks.hook(`frontgateConnection:response:${$.header.id_job}`,R=>{if(!R.Message.includes("HighLevelUpdate")){if(R.Message.includes("SubscriptionLoss")){this.log(f.DEBUG,`Received: ${R.Message}`),setTimeout(()=>{N()},Lt(u));return}this.log(f.ERROR,`Unexpected response: ${R.Message}`);const U=new z(R);y.pushError(U);return}let H;try{H=new tt(R)}catch(U){this.log(f.ERROR,`Failed to parse response: ${R.body.value}`),y.pushError(U);return}y.pushPatchData(H.data)}),A()})});try{await Y(l,"Request timeout reached",C)}catch(A){m=!0,y.pushError(new z({Message:"Resubscribe failed",Error:A}))}},E=this.hooks.hook("reconnect:success",N);y.unsubscribe=()=>{if(this.#e.get(a)){const $=this.#t.get(a)??0;if(this.#t.set(a,$-1),$-1>0){this.log(f.INFO,`Not unsubscribing from ${a} as there are still ${$} subscribers`);return}this.#e.delete(a),this.#t.delete(a),m=!0}this.log(f.INFO,`Unsubscribing from ${a}`);const P={message:new ye(y.idJob).getPtlMessage(),callbackType:"job",callbackId:""};this.hooks.callHook("frontgateConnection:sendMessage",P),I(),E()},this.#e.set(a,y);const k=this.#t.get(a)??0;if(this.#t.set(a,k+1),m){this.log(f.WARN,`Zombie subscription detected for ${a}. Initiating unsubscribe.`),y.unsubscribe();return}d(y)})}).catch(g=>{v(g)})}),T=`Request timeout reached (${l} ms) for ${p.message.Message}`,_=Y(l,T,M).catch(d=>{throw m=!0,this.#t.delete(a),this.#e.delete(a),d}).finally(()=>{this.#r.delete(a)});return this.#r.set(a,_),_}}},{featureName:"EndpointSubscriptions",featureGroups:["Misc"]}),an=()=>j(e=>class extends e{#e=new Map;async observe(t,n=this.defaultTimeoutInMs){return this.#t(t,"job",void 0,n)}async observeConnectionBased(t,n,o=this.defaultTimeoutInMs){return this.#t(t,"connection",n,o)}async#t(t,n,o,s=this.defaultTimeoutInMs){const i=JSON.stringify(t.getPtlMessage());if(this.#e.has(i)){const h=this.#e.get(i);if(h)return h.count++,this.log(f.INFO,`Reusing existing subscription for ${i}`),h.observer}this.log(f.INFO,`Creating new subscription for ${i}`);const a={message:t.getPtlMessage(),callbackType:"job",callbackId:""};await this.hooks.callHook("frontgateConnection:sendMessage",a);const l=new Promise((h,p)=>{this.hooks.hookOnce(`frontgateConnection:response:${a.callbackId}`,m=>{if(m.Message.includes("Error")||m.Message.includes("PermissionDenied")){this.log(f.ERROR,`Unexpected response: ${m.Message}`),p(new Error(`Unexpected response: ${m.Message}`));return}const M=n==="connection"?`${m.header.id_service}-${t.getPtlMessage().id_notation}`:m.header.id_job,T=typeof o>"u"?new ye(m.header.id_job):new o(m.header.id_service,t.getPtlMessage().id_notation),_=new yt(m.header.id_job,m);let d=this.hooks.hook(`frontgateConnection:response:${M}`,g=>{if(g.Message.includes("Error")||g.Message.includes("PermissionDenied")){this.log(f.ERROR,`Unexpected response: ${m.Message}`),_.pushError(new z(JSON.stringify(g)));return}_.pushData(g)});const v=this.hooks.hook("reconnect:success",async()=>{d(),this.log(f.INFO,`Resubscribing to ${i} due to reconnect`),await this.hooks.callHook("frontgateConnection:sendMessage",a);const g=new Promise((w,y)=>{this.hooks.hookOnce(`frontgateConnection:response:${a.callbackId}`,I=>{if(I.Message.includes("Error")||I.Message.includes("PermissionDenied")){const k=new z(I);this.log(f.ERROR,`Unexpected resp: ${I.Message}`),y(k);return}const N=n==="connection"?`${I.header.id_service}-${t.getPtlMessage().id_notation}`:I.header.id_job,E=typeof o>"u"?new ye(I.header.id_job):new o(I.header.id_service,t.getPtlMessage().id_notation);_.idJob=I.header.id_job,d=this.hooks.hook(`frontgateConnection:response:${N}`,k=>{if(k.Message.includes("Error")||k.Message.includes("PermissionDenied")){this.log(f.ERROR,`Unexpected response: ${k.Message}`);const C=new z(k);_.pushError(C);return}_.unsubscribe=()=>{const C=this.#e.get(i);if(C){if(C.count--,C.count>0){this.log(f.INFO,`Not unsubscribing from ${i} as there are still ${C.count} subscribers`);return}this.#e.delete(i)}this.log(f.INFO,`Unsubscribing from ${i}`);const A={message:E.getPtlMessage(),callbackType:"job",callbackId:""};this.hooks.callHook("frontgateConnection:sendMessage",A),d(),v()},_.pushData(k)}),w()})});try{await Y(s,"Request timeout reached",g)}catch(w){_.pushError(new z({Message:"Reconnect failed",Error:w}))}});_.unsubscribe=()=>{const g=this.#e.get(i);if(g){if(g.count--,g.count>0){this.log(f.INFO,`Not unsubscribing from ${i} as there are still ${g.count} subscribers`);return}this.#e.delete(i)}this.log(f.INFO,`Unsubscribing from ${i}`);const w={message:T.getPtlMessage(),callbackType:"job",callbackId:""};this.hooks.callHook("frontgateConnection:sendMessage",w),d(),v()},this.#e.set(i,{observer:_,count:1}),h(_)})}),u=`Request timeout reached (${s} ms) for ${a.message.Message}`;return Y(s,u,l)}},{featureName:"RawSubscriptions",featureGroups:["Misc"]}),mt=(r,e)=>{const t=e.split("/").slice(1);let n=r;for(let o=0;o<t.length-1;o++){const s=decodeURIComponent(t[o]);if(!(s in n))throw new Error(`Path not found: ${e}`);n=n[s]}return[n,decodeURIComponent(t[t.length-1])]},cn=(r,e,t)=>{const[n,o]=mt(r,e);n[o]=t},un="-",hn=(r,e,t)=>{const[n,o]=mt(r,e);Array.isArray(n)?o===un?n.push(t):n.splice(parseInt(o,10),0,t):n[o]=t},ln=(r,e)=>{const[t,n]=mt(r,e);Array.isArray(t)?t.splice(parseInt(n,10),1):delete t[n]};function fn(r,e){return e.forEach(t=>{switch(t.op){case"replace":cn(r,t.path,t.value);break;case"add":hn(r,t.path,t.value);break;case"remove":ln(r,t.path);break;default:throw new Error(`Unsupported op: ${t.op}`)}}),r}class yt{#e;#t=[];#r=[];get data(){return this.#e}constructor(e,t){this.#e=t,this.idJob=e}subscribe({next:e,error:t}){e(this.#e),t&&this.#r.push(t),this.#t.push(e)}pushData(e){this.#e=e,this.#t.forEach(t=>{t(e)})}pushError(e){this.#r.forEach(t=>{t(e)})}}class ur extends yt{pushPatchData(e){try{const t=fn(this.data,e);super.pushData(t)}catch(t){super.pushError(new z(t.message))}}}const dn=r=>j(t=>class extends t{constructor(...n){super(...n),this.hooks.hook("frontgateConnection:beforeConnect",s=>{this.hooks.callHook("frontgateConnection:setIdApp",oe),this.hooks.callHook("frontgateConnection:setIdUser",ae),this.log(f.DEBUG,"Adding mdg2auth subprotocol"),s.subProtocols.push(`mdg2auth-${r}`)});const o=async s=>{this.hooks.callHook("frontgateConnection:setIdApp",oe),this.hooks.callHook("frontgateConnection:setIdUser",ae);const i={maximum_idle_interval:s.maximumIdleInterval},c={b64:""},l=new Ae(c,i.maximum_idle_interval).toJson();this.log(f.INFO,"Sending message",l);const u={message:l,callbackType:"response",callbackId:l.Message.replace("Request","Response")};await this.hooks.callHook("frontgateConnection:sendMessage",u),this.hooks.hookOnce(`frontgateConnection:response:${u.callbackId}`,h=>{this.log(f.INFO,"Received response",h),this.hooks.callHook("frontgateConnection:authenticated")})};this.hooks.hookOnce("frontgateConnection:connected",o)}},{featureName:"CookieTokenAuth",featureGroups:["Auth"],disabledFeatureGroups:["Auth"]}),gn=r=>j(t=>class extends t{#e;constructor(...n){super(...n),this.#e=r??"";const o=async s=>{this.hooks.callHook("frontgateConnection:setIdApp",oe),this.hooks.callHook("frontgateConnection:setIdUser",ae);const i={maximum_idle_interval:s.maximumIdleInterval},c={b64:this.#e},l=new Ae(c,i.maximum_idle_interval).toJson();this.log(f.INFO,"Sending message",l);const u={message:l,callbackType:"response",callbackId:l.Message.replace("Request","Response")};await this.hooks.callHook("frontgateConnection:sendMessage",u),this.hooks.hookOnce(`frontgateConnection:response:${u.callbackId}`,h=>{this.log(f.INFO,"Received response",h),this.hooks.callHook("frontgateConnection:authenticated")})};this.hooks.hook("frontgateConnection:connected",o)}set token(n){this.#e=n}},{featureName:"TokenAuth",featureGroups:["Auth"],disabledFeatureGroups:["Auth"]}),pn=(r,e,t)=>j(o=>class extends st({host:"",pathPrefix:"",port:0,tls:!0,maximumIdleIntervalInS:r.maximumIdleIntervalInS})(o){#e="";#t="";#r;#n;constructor(...s){super(...s),this.#r=e,this.#n=t,this.hooks.hook("frontgateConnection:beforeConnect",async c=>{this.hooks.callHook("frontgateConnection:setIdApp",oe),this.hooks.callHook("frontgateConnection:setIdUser",ae),this.log(f.DEBUG,"Fetching connection configuration");const a=await this.#o();if(this.log(f.DEBUG,"Connection configuration received",a),c.url=a.url,a.authtenticationType==="token"&&a.authenticationToken)this.#e=a.authenticationToken;else if(a.splitAuthenticationTokenSecondFactor)this.#t=a.splitAuthenticationTokenSecondFactor;else throw new Error("Invalid authentication configuration");this.log(f.DEBUG,"Adding mdg2auth subprotocol"),this.#t!==""&&c.subProtocols.push(`mdg2auth-${this.#t}`)});const i=async c=>{this.hooks.callHook("frontgateConnection:setIdApp",oe),this.hooks.callHook("frontgateConnection:setIdUser",ae);const a={maximum_idle_interval:c.maximumIdleInterval},l={b64:this.#e},h=new Ae(l,a.maximum_idle_interval).toJson();this.log(f.INFO,"Sending message",h);const p={message:h,callbackType:"response",callbackId:h.Message.replace("Request","Response")};await this.hooks.callHook("frontgateConnection:sendMessage",p),this.hooks.hookOnce(`frontgateConnection:response:${p.callbackId}`,m=>{this.log(f.INFO,"Received response",m),this.hooks.callHook("frontgateConnection:authenticated")})};this.hooks.hook("frontgateConnection:connected",i)}async#o(){const s=await fetch(this.#r,this.#n);if(!s.ok)throw new Error(`Failed to fetch connection configuration: ${s.status} ${s.statusText}`);const{headers:i}=s,c=i.get("frontgate-host"),a=i.get("frontgate-path-prefix"),l=i.get("frontgate-split-authentication-token-second-factor"),u=i.get("frontgate-authentication-type"),h=i.get("frontgate-authentication-token"),p=i.get("frontgate-websocket-port")??"443",m=`wss://${c}:${p}${a??""}/ws`;if(u==="token"&&!h)throw new Error("Authentication token is required for token authentication");if(u!=="token"&&!l)throw new Error("Split authentication token second factor is required");return{url:m,authtenticationType:u,authenticationToken:h,splitAuthenticationTokenSecondFactor:l}}},{featureName:"FetchAuth",featureGroups:["Auth","Connection"],disabledFeatureGroups:["Auth","Connection"]}),vn=(r,e,t)=>j(o=>class extends st({host:"",pathPrefix:"",port:0,tls:!0,maximumIdleIntervalInS:r.maximumIdleIntervalInS})(o){#e="";#t="";#r=!1;#n;#o;#s;constructor(...s){super(...s),this.#o=e,this.#s=t,this.#n=new cr,this.hooks.hook("frontgateConnection:reset",()=>{this.#r&&this.#n.reset()}),this.hooks.hook("frontgateConnection:beforeSendMessage",c=>{if(this.#r){const a=this.#n.compress(c.msg);c.msg=a}}),this.hooks.hook("frontgateConnection:afterReceiveMessage",c=>{if(this.#r){const a=this.#n.decompress(new Uint8Array(c.msg));c.msg=a}}),this.hooks.hook("frontgateConnection:beforeConnect",async c=>{this.hooks.callHook("frontgateConnection:setIdApp",oe),this.hooks.callHook("frontgateConnection:setIdUser",ae),this.log(f.DEBUG,"Fetching connection configuration");const a=await this.#i();if(this.log(f.DEBUG,"Connection configuration received",a),c.url=a.url,a.authtenticationType==="token"&&a.authenticationToken)this.#e=a.authenticationToken;else if(a.splitAuthenticationTokenSecondFactor)this.#t=a.splitAuthenticationTokenSecondFactor;else throw new Error("Invalid authentication configuration");this.log(f.DEBUG,"Adding mdg2auth subprotocol"),this.#t!==""&&c.subProtocols.push(`mdg2auth-${this.#t}`),this.#r&&c.subProtocols.forEach((l,u)=>{l.includes("jsjson")&&!l.includes("jsjsonc")&&(c.subProtocols[u]=l.replace("jsjson","jsjsonc"))})});const i=async c=>{this.hooks.callHook("frontgateConnection:setIdApp",oe),this.hooks.callHook("frontgateConnection:setIdUser",ae);const a={maximum_idle_interval:c.maximumIdleInterval},l={b64:this.#e},h=new Ae(l,a.maximum_idle_interval).toJson();this.log(f.INFO,"Sending message",h);const p={message:h,callbackType:"response",callbackId:h.Message.replace("Request","Response")};await this.hooks.callHook("frontgateConnection:sendMessage",p),this.hooks.hookOnce(`frontgateConnection:response:${p.callbackId}`,m=>{this.log(f.INFO,"Received response",m),this.hooks.callHook("frontgateConnection:authenticated")})};this.hooks.hook("frontgateConnection:connected",i)}async#i(){const s=await fetch(this.#o,this.#s);if(!s.ok)throw new Error(`Failed to fetch connection configuration: ${s.status} ${s.statusText}`);const{headers:i}=s,c=i.get("frontgate-host"),a=i.get("frontgate-path-prefix"),l=i.get("frontgate-split-authentication-token-second-factor"),u=i.get("frontgate-authentication-type"),h=i.get("frontgate-authentication-token"),p=i.get("frontgate-websocket-port")??"443",m=`wss://${c}:${p}${a??""}/ws`;if(u==="token"&&!h)throw new Error("Authentication token is required for token authentication");if(u!=="token"&&!l)throw new Error("Split authentication token second factor is required");return i.get("frontgate-websocket-protocol")==="jsjsonc-v2"?this.#r=!0:this.#r=!1,{url:m,authtenticationType:u,authenticationToken:h,splitAuthenticationTokenSecondFactor:l}}},{featureName:"FetchAuthWithOptionalCompressor",featureGroups:["Auth","Connection"],disabledFeatureGroups:["Auth","Connection","Compression"]}),bn=r=>j(t=>class extends t{#e=0;#t;#r;constructor(...n){super(...n),this.#t=r??[1e3,2e3,4e3,8e3,16e3,32e3];const o=s=>{if(s.code!==1e3){this.#r&&(this.log(f.WARN,"Aborting previous reconnect attempt"),clearTimeout(this.#r),this.#e=0);let i=this.#e;this.#e>=this.#t.length&&(i=this.#t.length-1);const c=this.#t[i];this.#r=setTimeout(()=>{this.log(f.INFO,`Reconnecting... Attempt ${this.#e}`);const a=this.hooks.hookOnce("reconnect:failed",o);this.hooks.callHook("reconnect:attempt",s).then(a).catch(()=>{this.log(f.ERROR,"Failed to reconnect")}),this.#r=void 0},c),this.#e++}};this.hooks.hookOnce("frontgateConnection:disconnected",o),this.hooks.hook("reconnect:success",()=>{clearTimeout(this.#r),this.#r=void 0,this.#e=0,this.log(f.INFO,"Reconnected"),this.hooks.hookOnce("frontgateConnection:disconnected",o)})}},{featureName:"Reconnect",featureGroups:["Misc"],disabledFeatures:["TokenAuth","CookieTokenAuth"]});var mn=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof window=="object"?window:typeof global=="object"?global:{},pe="1.9.0",hr=/^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;function yn(r){var e=new Set([r]),t=new Set,n=r.match(hr);if(!n)return function(){return!1};var o={major:+n[1],minor:+n[2],patch:+n[3],prerelease:n[4]};if(o.prerelease!=null)return function(a){return a===r};function s(c){return t.add(c),!1}function i(c){return e.add(c),!0}return function(a){if(e.has(a))return!0;if(t.has(a))return!1;var l=a.match(hr);if(!l)return s(a);var u={major:+l[1],minor:+l[2],patch:+l[3],prerelease:l[4]};return u.prerelease!=null||o.major!==u.major?s(a):o.major===0?o.minor===u.minor&&o.patch<=u.patch?i(a):s(a):o.minor<=u.minor?i(a):s(a)}}var kn=yn(pe),wn=pe.split(".")[0],Se=Symbol.for("opentelemetry.js.api."+wn),Pe=mn;function xe(r,e,t,n){var o;n===void 0&&(n=!1);var s=Pe[Se]=(o=Pe[Se])!==null&&o!==void 0?o:{version:pe};if(!n&&s[r]){var i=new Error("@opentelemetry/api: Attempted duplicate registration of API: "+r);return t.error(i.stack||i.message),!1}if(s.version!==pe){var i=new Error("@opentelemetry/api: Registration of version v"+s.version+" for "+r+" does not match previously registered API v"+pe);return t.error(i.stack||i.message),!1}return s[r]=e,t.debug("@opentelemetry/api: Registered a global for "+r+" v"+pe+"."),!0}function ve(r){var e,t,n=(e=Pe[Se])===null||e===void 0?void 0:e.version;if(!(!n||!kn(n)))return(t=Pe[Se])===null||t===void 0?void 0:t[r]}function Fe(r,e){e.debug("@opentelemetry/api: Unregistering a global for "+r+" v"+pe+".");var t=Pe[Se];t&&delete t[r]}var _n=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),o,s=[],i;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)s.push(o.value)}catch(c){i={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(i)throw i.error}}return s},Mn=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,s;n<o;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},En=(function(){function r(e){this._namespace=e.namespace||"DiagComponentLogger"}return r.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return $e("debug",this._namespace,e)},r.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return $e("error",this._namespace,e)},r.prototype.info=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return $e("info",this._namespace,e)},r.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return $e("warn",this._namespace,e)},r.prototype.verbose=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return $e("verbose",this._namespace,e)},r})();function $e(r,e,t){var n=ve("diag");if(n)return t.unshift(e),n[r].apply(n,Mn([],_n(t),!1))}var B;(function(r){r[r.NONE=0]="NONE",r[r.ERROR=30]="ERROR",r[r.WARN=50]="WARN",r[r.INFO=60]="INFO",r[r.DEBUG=70]="DEBUG",r[r.VERBOSE=80]="VERBOSE",r[r.ALL=9999]="ALL"})(B||(B={}));function Tn(r,e){r<B.NONE?r=B.NONE:r>B.ALL&&(r=B.ALL),e=e||{};function t(n,o){var s=e[n];return typeof s=="function"&&r>=o?s.bind(e):function(){}}return{error:t("error",B.ERROR),warn:t("warn",B.WARN),info:t("info",B.INFO),debug:t("debug",B.DEBUG),verbose:t("verbose",B.VERBOSE)}}var In=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),o,s=[],i;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)s.push(o.value)}catch(c){i={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(i)throw i.error}}return s},Cn=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,s;n<o;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},An="diag",re=(function(){function r(){function e(o){return function(){for(var s=[],i=0;i<arguments.length;i++)s[i]=arguments[i];var c=ve("diag");if(c)return c[o].apply(c,Cn([],In(s),!1))}}var t=this,n=function(o,s){var i,c,a;if(s===void 0&&(s={logLevel:B.INFO}),o===t){var l=new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");return t.error((i=l.stack)!==null&&i!==void 0?i:l.message),!1}typeof s=="number"&&(s={logLevel:s});var u=ve("diag"),h=Tn((c=s.logLevel)!==null&&c!==void 0?c:B.INFO,o);if(u&&!s.suppressOverrideMessage){var p=(a=new Error().stack)!==null&&a!==void 0?a:"<failed to generate stacktrace>";u.warn("Current logger will be overwritten from "+p),h.warn("Current logger will overwrite one already registered from "+p)}return xe("diag",h,t,!0)};t.setLogger=n,t.disable=function(){Fe(An,t)},t.createComponentLogger=function(o){return new En(o)},t.verbose=e("verbose"),t.debug=e("debug"),t.info=e("info"),t.warn=e("warn"),t.error=e("error")}return r.instance=function(){return this._instance||(this._instance=new r),this._instance},r})(),Rn=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),o,s=[],i;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)s.push(o.value)}catch(c){i={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(i)throw i.error}}return s},On=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Nn=(function(){function r(e){this._entries=e?new Map(e):new Map}return r.prototype.getEntry=function(e){var t=this._entries.get(e);if(t)return Object.assign({},t)},r.prototype.getAllEntries=function(){return Array.from(this._entries.entries()).map(function(e){var t=Rn(e,2),n=t[0],o=t[1];return[n,o]})},r.prototype.setEntry=function(e,t){var n=new r(this._entries);return n._entries.set(e,t),n},r.prototype.removeEntry=function(e){var t=new r(this._entries);return t._entries.delete(e),t},r.prototype.removeEntries=function(){for(var e,t,n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];var s=new r(this._entries);try{for(var i=On(n),c=i.next();!c.done;c=i.next()){var a=c.value;s._entries.delete(a)}}catch(l){e={error:l}}finally{try{c&&!c.done&&(t=i.return)&&t.call(i)}finally{if(e)throw e.error}}return s},r.prototype.clear=function(){return new r},r})();re.instance();function Sn(r){return r===void 0&&(r={}),new Nn(new Map(Object.entries(r)))}function lr(r){return Symbol.for(r)}var Pn=(function(){function r(e){var t=this;t._currentContext=e?new Map(e):new Map,t.getValue=function(n){return t._currentContext.get(n)},t.setValue=function(n,o){var s=new r(t._currentContext);return s._currentContext.set(n,o),s},t.deleteValue=function(n){var o=new r(t._currentContext);return o._currentContext.delete(n),o}}return r})(),xn=new Pn,be=(function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var s in o)Object.prototype.hasOwnProperty.call(o,s)&&(n[s]=o[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}})(),Fn=(function(){function r(){}return r.prototype.createGauge=function(e,t){return Vn},r.prototype.createHistogram=function(e,t){return Wn},r.prototype.createCounter=function(e,t){return Bn},r.prototype.createUpDownCounter=function(e,t){return Jn},r.prototype.createObservableGauge=function(e,t){return Kn},r.prototype.createObservableCounter=function(e,t){return zn},r.prototype.createObservableUpDownCounter=function(e,t){return Yn},r.prototype.addBatchObservableCallback=function(e,t){},r.prototype.removeBatchObservableCallback=function(e){},r})(),Ke=(function(){function r(){}return r})(),$n=(function(r){be(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e.prototype.add=function(t,n){},e})(Ke),Un=(function(r){be(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e.prototype.add=function(t,n){},e})(Ke),Dn=(function(r){be(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e.prototype.record=function(t,n){},e})(Ke),jn=(function(r){be(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e.prototype.record=function(t,n){},e})(Ke),kt=(function(){function r(){}return r.prototype.addCallback=function(e){},r.prototype.removeCallback=function(e){},r})(),Hn=(function(r){be(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(kt),Gn=(function(r){be(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(kt),qn=(function(r){be(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(kt),Ln=new Fn,Bn=new $n,Vn=new Dn,Wn=new jn,Jn=new Un,zn=new Hn,Kn=new Gn,Yn=new qn,Qn={get:function(r,e){if(r!=null)return r[e]},keys:function(r){return r==null?[]:Object.keys(r)}},Xn={set:function(r,e,t){r!=null&&(r[e]=t)}},Zn=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),o,s=[],i;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)s.push(o.value)}catch(c){i={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(i)throw i.error}}return s},eo=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,s;n<o;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},to=(function(){function r(){}return r.prototype.active=function(){return xn},r.prototype.with=function(e,t,n){for(var o=[],s=3;s<arguments.length;s++)o[s-3]=arguments[s];return t.call.apply(t,eo([n],Zn(o),!1))},r.prototype.bind=function(e,t){return t},r.prototype.enable=function(){return this},r.prototype.disable=function(){return this},r})(),ro=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),o,s=[],i;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)s.push(o.value)}catch(c){i={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(i)throw i.error}}return s},no=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,s;n<o;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},wt="context",oo=new to,Ye=(function(){function r(){}return r.getInstance=function(){return this._instance||(this._instance=new r),this._instance},r.prototype.setGlobalContextManager=function(e){return xe(wt,e,re.instance())},r.prototype.active=function(){return this._getContextManager().active()},r.prototype.with=function(e,t,n){for(var o,s=[],i=3;i<arguments.length;i++)s[i-3]=arguments[i];return(o=this._getContextManager()).with.apply(o,no([e,t,n],ro(s),!1))},r.prototype.bind=function(e,t){return this._getContextManager().bind(e,t)},r.prototype._getContextManager=function(){return ve(wt)||oo},r.prototype.disable=function(){this._getContextManager().disable(),Fe(wt,re.instance())},r})(),_t;(function(r){r[r.NONE=0]="NONE",r[r.SAMPLED=1]="SAMPLED"})(_t||(_t={}));var fr="0000000000000000",dr="00000000000000000000000000000000",so={traceId:dr,spanId:fr,traceFlags:_t.NONE},Ue=(function(){function r(e){e===void 0&&(e=so),this._spanContext=e}return r.prototype.spanContext=function(){return this._spanContext},r.prototype.setAttribute=function(e,t){return this},r.prototype.setAttributes=function(e){return this},r.prototype.addEvent=function(e,t){return this},r.prototype.addLink=function(e){return this},r.prototype.addLinks=function(e){return this},r.prototype.setStatus=function(e){return this},r.prototype.updateName=function(e){return this},r.prototype.end=function(e){},r.prototype.isRecording=function(){return!1},r.prototype.recordException=function(e,t){},r})(),Mt=lr("OpenTelemetry Context Key SPAN");function Et(r){return r.getValue(Mt)||void 0}function io(){return Et(Ye.getInstance().active())}function Tt(r,e){return r.setValue(Mt,e)}function ao(r){return r.deleteValue(Mt)}function co(r,e){return Tt(r,new Ue(e))}function gr(r){var e;return(e=Et(r))===null||e===void 0?void 0:e.spanContext()}var uo=/^([0-9a-f]{32})$/i,ho=/^[0-9a-f]{16}$/i;function lo(r){return uo.test(r)&&r!==dr}function fo(r){return ho.test(r)&&r!==fr}function pr(r){return lo(r.traceId)&&fo(r.spanId)}function go(r){return new Ue(r)}var It=Ye.getInstance(),vr=(function(){function r(){}return r.prototype.startSpan=function(e,t,n){n===void 0&&(n=It.active());var o=!!t?.root;if(o)return new Ue;var s=n&&gr(n);return po(s)&&pr(s)?new Ue(s):new Ue},r.prototype.startActiveSpan=function(e,t,n,o){var s,i,c;if(!(arguments.length<2)){arguments.length===2?c=t:arguments.length===3?(s=t,c=n):(s=t,i=n,c=o);var a=i??It.active(),l=this.startSpan(e,s,a),u=Tt(a,l);return It.with(u,c,void 0,l)}},r})();function po(r){return typeof r=="object"&&typeof r.spanId=="string"&&typeof r.traceId=="string"&&typeof r.traceFlags=="number"}var vo=new vr,bo=(function(){function r(e,t,n,o){this._provider=e,this.name=t,this.version=n,this.options=o}return r.prototype.startSpan=function(e,t,n){return this._getTracer().startSpan(e,t,n)},r.prototype.startActiveSpan=function(e,t,n,o){var s=this._getTracer();return Reflect.apply(s.startActiveSpan,s,arguments)},r.prototype._getTracer=function(){if(this._delegate)return this._delegate;var e=this._provider.getDelegateTracer(this.name,this.version,this.options);return e?(this._delegate=e,this._delegate):vo},r})(),mo=(function(){function r(){}return r.prototype.getTracer=function(e,t,n){return new vr},r})(),yo=new mo,br=(function(){function r(){}return r.prototype.getTracer=function(e,t,n){var o;return(o=this.getDelegateTracer(e,t,n))!==null&&o!==void 0?o:new bo(this,e,t,n)},r.prototype.getDelegate=function(){var e;return(e=this._delegate)!==null&&e!==void 0?e:yo},r.prototype.setDelegate=function(e){this._delegate=e},r.prototype.getDelegateTracer=function(e,t,n){var o;return(o=this._delegate)===null||o===void 0?void 0:o.getTracer(e,t,n)},r})();Ye.getInstance(),re.instance();var ko=(function(){function r(){}return r.prototype.getMeter=function(e,t,n){return Ln},r})(),wo=new ko,Ct="metrics",_o=(function(){function r(){}return r.getInstance=function(){return this._instance||(this._instance=new r),this._instance},r.prototype.setGlobalMeterProvider=function(e){return xe(Ct,e,re.instance())},r.prototype.getMeterProvider=function(){return ve(Ct)||wo},r.prototype.getMeter=function(e,t,n){return this.getMeterProvider().getMeter(e,t,n)},r.prototype.disable=function(){Fe(Ct,re.instance())},r})();_o.getInstance();var Mo=(function(){function r(){}return r.prototype.inject=function(e,t){},r.prototype.extract=function(e,t){return e},r.prototype.fields=function(){return[]},r})(),At=lr("OpenTelemetry Baggage Key");function mr(r){return r.getValue(At)||void 0}function Eo(){return mr(Ye.getInstance().active())}function To(r,e){return r.setValue(At,e)}function Io(r){return r.deleteValue(At)}var Rt="propagation",Co=new Mo,Ao=(function(){function r(){this.createBaggage=Sn,this.getBaggage=mr,this.getActiveBaggage=Eo,this.setBaggage=To,this.deleteBaggage=Io}return r.getInstance=function(){return this._instance||(this._instance=new r),this._instance},r.prototype.setGlobalPropagator=function(e){return xe(Rt,e,re.instance())},r.prototype.inject=function(e,t,n){return n===void 0&&(n=Xn),this._getGlobalPropagator().inject(e,t,n)},r.prototype.extract=function(e,t,n){return n===void 0&&(n=Qn),this._getGlobalPropagator().extract(e,t,n)},r.prototype.fields=function(){return this._getGlobalPropagator().fields()},r.prototype.disable=function(){Fe(Rt,re.instance())},r.prototype._getGlobalPropagator=function(){return ve(Rt)||Co},r})();Ao.getInstance();var Ot="trace",Ro=(function(){function r(){this._proxyTracerProvider=new br,this.wrapSpanContext=go,this.isSpanContextValid=pr,this.deleteSpan=ao,this.getSpan=Et,this.getActiveSpan=io,this.getSpanContext=gr,this.setSpan=Tt,this.setSpanContext=co}return r.getInstance=function(){return this._instance||(this._instance=new r),this._instance},r.prototype.setGlobalTracerProvider=function(e){var t=xe(Ot,this._proxyTracerProvider,re.instance());return t&&this._proxyTracerProvider.setDelegate(e),t},r.prototype.getTracerProvider=function(){return ve(Ot)||this._proxyTracerProvider},r.prototype.getTracer=function(e,t){return this.getTracerProvider().getTracer(e,t)},r.prototype.disable=function(){Fe(Ot,re.instance()),this._proxyTracerProvider=new br},r})(),Oo=Ro.getInstance();const No=()=>j(e=>class extends e{constructor(...t){super(...t),this.hooks.hook("frontgateConnection:beforeSerializeMessage",n=>{n.header&&Oo.getTracer("frontgate-js-sdk").startActiveSpan("frontgateConnection:sendMessage",o=>{const s=this.#e(o.spanContext());s&&(n.header={...n.header,...s}),o.end()})})}#e(t){if(!/^0+$/.test(t.traceId))return{tracing:{value:{value:yr(t)}}}}},{featureName:"OpenTelemetry",featureGroups:["Misc"]}),yr=r=>{const e=[18,20,9],t=n=>{for(let o=n.length;o>n.length-16;o-=2){let s=parseInt(n.substring(o-2,o),16);s>127&&(s-=256),e.push(s)}};return t(r.traceId),e.push(17),t(r.spanId),e.push(24),e.push(0),e},So=()=>j(e=>class extends e{async requestProxyEndpoint(t,n,o,s,i=this.defaultTimeoutInMs){const c=new Be(t,n,s);o&&c.setBody(o),c.header.setTimeout(i);const a={message:c.getPtlMessage(),callbackType:"job",callbackId:""};await this.hooks.callHook("frontgateConnection:sendMessage",a);const l=new Promise((h,p)=>{this.hooks.hookOnce(`frontgateConnection:response:${a.callbackId}`,m=>{try{if(!m.Message.includes("HTTPProxyResponse")){p(JSON.stringify(m));return}const M=new zt(m);h({response:M,data:M.data})}catch(M){p(M)}})}),u=`Request timeout reached (${i} ms) for ${a.message.Message}`;return Y(i,u,l)}},{featureName:"HTTPProxyRequest",featureGroups:["Misc"]}),Po=()=>j(e=>class extends e{async ping(t=this.defaultTimeoutInMs){const o={message:new Ve().getPtlMessage(),callbackType:"response",callbackId:"PingResponse"};await this.hooks.callHook("frontgateConnection:sendMessage",o);const s=new Promise(c=>{this.hooks.hookOnce(`frontgateConnection:response:${o.callbackId}`,a=>{const l=new We(a);c(l)})}),i=`Request timeout reached (${t} ms) for ${o.message.Message}`;return Y(t,i,s)}},{featureName:"Pingable",featureGroups:["Misc"]}),xo=r=>j(t=>class extends t{async logRemotely(n){const s={message:new Vt({Message:"LogMessage",timestamp:{microseconds:Date.now()*1e3},uuid:{id_1:r??0,id_2:0},level:{value:4},area:61,Version:1,message:n}).getPtlMessage(),callbackType:"job",callbackId:""};return this.hooks.callHook("frontgateConnection:sendMessage",s)}},{featureName:"RemoteLogger",featureGroups:["Misc"]}),j=(r,e)=>{const t=r;return t.featureName=e.featureName,t.featureGroups=e.featureGroups,t.disabledFeatures=e.disabledFeatures,t.disabledFeatureGroups=e.disabledFeatureGroups,t};function Nt(r,e={},t){for(const n in r){const o=r[n],s=t?`${t}:${n}`:n;typeof o=="object"&&o!==null?Nt(o,e,s):typeof o=="function"&&(e[s]=o)}return e}const Fo={run:r=>r()},$o=()=>Fo,kr=typeof console.createTask<"u"?console.createTask:$o;function Uo(r,e){const t=e.shift(),n=kr(t);return r.reduce((o,s)=>o.then(()=>n.run(()=>s(...e))),Promise.resolve())}function Do(r,e){const t=e.shift(),n=kr(t);return Promise.all(r.map(o=>n.run(()=>o(...e))))}function St(r,e){for(const t of[...r])t(e)}class jo{constructor(){this._hooks={},this._before=void 0,this._after=void 0,this._deprecatedMessages=void 0,this._deprecatedHooks={},this.hook=this.hook.bind(this),this.callHook=this.callHook.bind(this),this.callHookWith=this.callHookWith.bind(this)}hook(e,t,n={}){if(!e||typeof t!="function")return()=>{};const o=e;let s;for(;this._deprecatedHooks[e];)s=this._deprecatedHooks[e],e=s.to;if(s&&!n.allowDeprecated){let i=s.message;i||(i=`${o} hook has been deprecated`+(s.to?`, please use ${s.to}`:"")),this._deprecatedMessages||(this._deprecatedMessages=new Set),this._deprecatedMessages.has(i)||(console.warn(i),this._deprecatedMessages.add(i))}if(!t.name)try{Object.defineProperty(t,"name",{get:()=>"_"+e.replace(/\W+/g,"_")+"_hook_cb",configurable:!0})}catch{}return this._hooks[e]=this._hooks[e]||[],this._hooks[e].push(t),()=>{t&&(this.removeHook(e,t),t=void 0)}}hookOnce(e,t){let n,o=(...s)=>(typeof n=="function"&&n(),n=void 0,o=void 0,t(...s));return n=this.hook(e,o),n}removeHook(e,t){if(this._hooks[e]){const n=this._hooks[e].indexOf(t);n!==-1&&this._hooks[e].splice(n,1),this._hooks[e].length===0&&delete this._hooks[e]}}deprecateHook(e,t){this._deprecatedHooks[e]=typeof t=="string"?{to:t}:t;const n=this._hooks[e]||[];delete this._hooks[e];for(const o of n)this.hook(e,o)}deprecateHooks(e){Object.assign(this._deprecatedHooks,e);for(const t in e)this.deprecateHook(t,e[t])}addHooks(e){const t=Nt(e),n=Object.keys(t).map(o=>this.hook(o,t[o]));return()=>{for(const o of n.splice(0,n.length))o()}}removeHooks(e){const t=Nt(e);for(const n in t)this.removeHook(n,t[n])}removeAllHooks(){for(const e in this._hooks)delete this._hooks[e]}callHook(e,...t){return t.unshift(e),this.callHookWith(Uo,e,...t)}callHookParallel(e,...t){return t.unshift(e),this.callHookWith(Do,e,...t)}callHookWith(e,t,...n){const o=this._before||this._after?{name:t,args:n,context:{}}:void 0;this._before&&St(this._before,o);const s=e(t in this._hooks?[...this._hooks[t]]:[],n);return s instanceof Promise?s.finally(()=>{this._after&&o&&St(this._after,o)}):(this._after&&o&&St(this._after,o),s)}beforeEach(e){return this._before=this._before||[],this._before.push(e),()=>{if(this._before!==void 0){const t=this._before.indexOf(e);t!==-1&&this._before.splice(t,1)}}}afterEach(e){return this._after=this._after||[],this._after.push(e),()=>{if(this._after!==void 0){const t=this._after.indexOf(e);t!==-1&&this._after.splice(t,1)}}}}function Ho(){return new jo}const wr=typeof window<"u";function Go(r,e={}){const t={inspect:wr,group:wr,filter:()=>!0,...e},n=t.filter,o=typeof n=="string"?u=>u.startsWith(n):n,s=t.tag?`[${t.tag}] `:"",i=u=>s+u.name+"".padEnd(u._id,"\0"),c={},a=r.beforeEach(u=>{o!==void 0&&!o(u.name)||(c[u.name]=c[u.name]||0,u._id=c[u.name]++,console.time(i(u)))}),l=r.afterEach(u=>{o!==void 0&&!o(u.name)||(t.group&&console.groupCollapsed(u.name),t.inspect?console.timeLog(i(u),u.args):console.timeEnd(i(u)),t.group&&console.groupEnd(),c[u.name]--)});return{close:()=>{a(),l()}}}class _r{constructor(e){this.hooks=Ho(),this.#e=1e4,e?.hookDebug&&Go(this.hooks,{tag:"hooks"}),e?.defaultRequestTimeout&&(this.#e=e.defaultRequestTimeout)}#e;get defaultTimeoutInMs(){return this.#e}log(e,...t){if(this.hooks.callHook("base:log",t),this.logger)switch(e){case f.TRACE:this.logger.trace(t);break;case f.DEBUG:this.logger.debug(t);break;case f.INFO:this.logger.info(t);break;case f.WARN:this.logger.warn(t);break;case f.ERROR:this.logger.error(t);break;case f.FATAL:this.logger.fatal(t);break}}}class Qe{#e;#t=[];#r=[];#n=[];constructor(e,t=[],n=[],o=[]){this.#e=e,this.#t=t,this.#r=n,this.#n=o}static create(){return new Qe(_r)}#o(e){if(this.#t.includes(e))throw new Error(`Feature "${e}" has already been used.`)}#s(e){for(const t of this.#r)if(t.feature===e)throw new Error(`Feature "${e}" has been disabled by ${t.disabler.join(",")}.`)}#i(e){for(const t of this.#n)if(t.feature===e)throw new Error(`Group "${e}" has been disabled by ${t.disabler.join(",")}.`)}#a(e,t){for(const n of this.#r)if(n.feature===t){n.disabler.push(e);return}this.#r.push({disabler:[e],feature:t})}#c(e,t){for(const n of this.#n)if(n.feature===t){n.disabler.push(e);return}this.#n.push({disabler:[e],feature:t})}with(e){const{featureName:t,disabledFeatures:n,disabledFeatureGroups:o,featureGroups:s}=e;if(!t)throw new Error("Feature name is missing");if(t!=="Custom"){if(this.#o(t),this.#s(t),this.#t.push(t),s&&s.length>0)for(const c of s)this.#i(c);if(n&&n.length>0)for(const c of n)this.#a(t,c);if(o&&o.length>0)for(const c of o)this.#c(t,c)}const i=e(this.#e);return new Qe(i,this.#t,this.#r,this.#n)}build(e){return new this.#e(e)}getClientConstructor(){return this.#e}}b.AbstractLogger=ce,b.AbstractMdg2Request=me,b.AuthenticationByTokenRequest=Ae,b.AuthenticationTokenRequest=Le,b.AuthenticationTokenResponse=Wt,b.CancelSubscriptionRequest=ye,b.ConnectionState=Dt,b.ConsoleLogger=nt,b.CookieTokenAuthenticationFactors=$t,b.DEFAULT_TIMEOUT_IN_MS=Bt,b.DefaultHosts=Ht,b.DeploymentStage=jt,b.ErrorResponse=z,b.FLAG_HAS_NEXT_CHUNK=rt,b.FrontgateClient=_r,b.FrontgateClientBuilder=Qe,b.FrontgateClientDataObserver=yt,b.FrontgateClientEndpointDataObserver=ur,b.HTTPProxyRequest=Be,b.HTTPProxyResponse=zt,b.HighLevelRequest=ke,b.HighLevelResponse=Jt,b.HighLevelUpdate=tt,b.ID_APP_AUTHENTICATED=oe,b.ID_USER_AUTHENTICATED=ae,b.ID_USER_NONE=Ut,b.LogLevel=f,b.LoggerHelper=Pr,b.Mdg2Response=fe,b.NullLogger=ot,b.PingRequest=Ve,b.PingResponse=We,b.RawRequest=Vt,b.TimeOptions=Gt,b.TransportLayerClientRequestHeader=qe,b.WinstonLogger=Fr,b.authTokenRequest=$r,b.cookieTokenAuth=dn,b.createExtendedMixinFactory=j,b.encodeSpanContext=yr,b.endpointRequest=Ur,b.endpointSubscriptions=sn,b.fetchAuth=pn,b.fetchAuthWithOptionalCompressor=vn,b.getBytesFromBuffer=Ar,b.httpProxyRequest=So,b.levels=xr,b.logger=Dr,b.messageCompressor=nn,b.openTelemetry=No,b.pingRequests=Po,b.rawSubscriptions=an,b.reconnect=bn,b.remotelogger=xo,b.requests=on,b.timeToMilliseconds=Ge,b.tokenAuth=gn,b.useTimeout=Y,b.wsConnection=st,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
function timeToMilliseconds(time) {
|
|
176
176
|
return time.toString().slice(0, -3);
|
|
177
177
|
}
|
|
178
|
-
const PACKAGE_JSON = { version: "7.0
|
|
178
|
+
const PACKAGE_JSON = { version: "7.1.0", package: "@factset/frontgate-js-sdk" };
|
|
179
179
|
function getClientInformation() {
|
|
180
180
|
const navigator2 = getNavigator();
|
|
181
181
|
return {
|
|
@@ -2441,7 +2441,7 @@
|
|
|
2441
2441
|
};
|
|
2442
2442
|
return createExtendedMixinFactory(mixinCompressor, {
|
|
2443
2443
|
featureName: "MessageCompressor",
|
|
2444
|
-
featureGroups: ["
|
|
2444
|
+
featureGroups: ["Compression"]
|
|
2445
2445
|
});
|
|
2446
2446
|
};
|
|
2447
2447
|
const requests = () => {
|
|
@@ -2571,6 +2571,14 @@
|
|
|
2571
2571
|
res();
|
|
2572
2572
|
return;
|
|
2573
2573
|
}
|
|
2574
|
+
try {
|
|
2575
|
+
observer.pushData(JSON.parse(resp.body.value));
|
|
2576
|
+
} catch (e) {
|
|
2577
|
+
this.log(LogLevel.ERROR, `Failed to parse response: ${resp.body.value}`);
|
|
2578
|
+
this.log(LogLevel.ERROR, e);
|
|
2579
|
+
rej(e);
|
|
2580
|
+
return;
|
|
2581
|
+
}
|
|
2574
2582
|
removeMessageUpdateHook = this.hooks.hook(`frontgateConnection:response:${resp.header.id_job}`, (update) => {
|
|
2575
2583
|
if (!update.Message.includes("HighLevelUpdate")) {
|
|
2576
2584
|
if (update.Message.includes("SubscriptionLoss")) {
|
|
@@ -3088,6 +3096,153 @@
|
|
|
3088
3096
|
disabledFeatureGroups: ["Auth", "Connection"]
|
|
3089
3097
|
});
|
|
3090
3098
|
};
|
|
3099
|
+
const fetchAuthWithOptionalCompressor = (config, input, init) => {
|
|
3100
|
+
const mixinFetchAuth = (Base) => {
|
|
3101
|
+
return class extends wsConnection({
|
|
3102
|
+
host: "",
|
|
3103
|
+
pathPrefix: "",
|
|
3104
|
+
port: 0,
|
|
3105
|
+
tls: true,
|
|
3106
|
+
maximumIdleIntervalInS: config.maximumIdleIntervalInS
|
|
3107
|
+
})(Base) {
|
|
3108
|
+
#token = "";
|
|
3109
|
+
#secondFactor = "";
|
|
3110
|
+
#shouldCompress = false;
|
|
3111
|
+
#compressor;
|
|
3112
|
+
#requestInfo;
|
|
3113
|
+
#requestInit;
|
|
3114
|
+
constructor(...args) {
|
|
3115
|
+
super(...args);
|
|
3116
|
+
this.#requestInfo = input;
|
|
3117
|
+
this.#requestInit = init;
|
|
3118
|
+
this.#compressor = new Compressor();
|
|
3119
|
+
this.hooks.hook("frontgateConnection:reset", () => {
|
|
3120
|
+
if (this.#shouldCompress) {
|
|
3121
|
+
this.#compressor.reset();
|
|
3122
|
+
}
|
|
3123
|
+
});
|
|
3124
|
+
this.hooks.hook("frontgateConnection:beforeSendMessage", (data) => {
|
|
3125
|
+
if (this.#shouldCompress) {
|
|
3126
|
+
const compressed = this.#compressor.compress(data.msg);
|
|
3127
|
+
data.msg = compressed;
|
|
3128
|
+
}
|
|
3129
|
+
});
|
|
3130
|
+
this.hooks.hook("frontgateConnection:afterReceiveMessage", (data) => {
|
|
3131
|
+
if (this.#shouldCompress) {
|
|
3132
|
+
const decompressed = this.#compressor.decompress(new Uint8Array(data.msg));
|
|
3133
|
+
data.msg = decompressed;
|
|
3134
|
+
}
|
|
3135
|
+
});
|
|
3136
|
+
this.hooks.hook("frontgateConnection:beforeConnect", async (settings) => {
|
|
3137
|
+
void this.hooks.callHook("frontgateConnection:setIdApp", ID_APP_AUTHENTICATED);
|
|
3138
|
+
void this.hooks.callHook("frontgateConnection:setIdUser", ID_USER_AUTHENTICATED);
|
|
3139
|
+
this.log(LogLevel.DEBUG, "Fetching connection configuration");
|
|
3140
|
+
const fetchConfig = await this.#fetchConnectionConfiguration();
|
|
3141
|
+
this.log(LogLevel.DEBUG, "Connection configuration received", fetchConfig);
|
|
3142
|
+
settings.url = fetchConfig.url;
|
|
3143
|
+
if (fetchConfig.authtenticationType === "token" && fetchConfig.authenticationToken) {
|
|
3144
|
+
this.#token = fetchConfig.authenticationToken;
|
|
3145
|
+
} else if (fetchConfig.splitAuthenticationTokenSecondFactor) {
|
|
3146
|
+
this.#secondFactor = fetchConfig.splitAuthenticationTokenSecondFactor;
|
|
3147
|
+
} else {
|
|
3148
|
+
throw new Error("Invalid authentication configuration");
|
|
3149
|
+
}
|
|
3150
|
+
this.log(LogLevel.DEBUG, "Adding mdg2auth subprotocol");
|
|
3151
|
+
if (this.#secondFactor !== "") {
|
|
3152
|
+
settings.subProtocols.push(`mdg2auth-${this.#secondFactor}`);
|
|
3153
|
+
}
|
|
3154
|
+
if (this.#shouldCompress) {
|
|
3155
|
+
settings.subProtocols.forEach((protocol, index) => {
|
|
3156
|
+
if (protocol.includes("jsjson") && !protocol.includes("jsjsonc")) {
|
|
3157
|
+
settings.subProtocols[index] = protocol.replace("jsjson", "jsjsonc");
|
|
3158
|
+
}
|
|
3159
|
+
});
|
|
3160
|
+
}
|
|
3161
|
+
});
|
|
3162
|
+
const authFn = async (conf) => {
|
|
3163
|
+
void this.hooks.callHook("frontgateConnection:setIdApp", ID_APP_AUTHENTICATED);
|
|
3164
|
+
void this.hooks.callHook("frontgateConnection:setIdUser", ID_USER_AUTHENTICATED);
|
|
3165
|
+
const options = {
|
|
3166
|
+
maximum_idle_interval: conf.maximumIdleInterval
|
|
3167
|
+
};
|
|
3168
|
+
const tokenData = { b64: this.#token };
|
|
3169
|
+
const request = new AuthenticationByTokenRequest(tokenData, options.maximum_idle_interval);
|
|
3170
|
+
const message = request.toJson();
|
|
3171
|
+
this.log(LogLevel.INFO, "Sending message", message);
|
|
3172
|
+
const msg = {
|
|
3173
|
+
message,
|
|
3174
|
+
callbackType: "response",
|
|
3175
|
+
callbackId: message.Message.replace("Request", "Response")
|
|
3176
|
+
};
|
|
3177
|
+
await this.hooks.callHook("frontgateConnection:sendMessage", msg);
|
|
3178
|
+
this.hooks.hookOnce(`frontgateConnection:response:${msg.callbackId}`, (response) => {
|
|
3179
|
+
this.log(LogLevel.INFO, "Received response", response);
|
|
3180
|
+
void this.hooks.callHook("frontgateConnection:authenticated");
|
|
3181
|
+
});
|
|
3182
|
+
};
|
|
3183
|
+
this.hooks.hook("frontgateConnection:connected", authFn);
|
|
3184
|
+
}
|
|
3185
|
+
async #fetchConnectionConfiguration() {
|
|
3186
|
+
const response = await fetch(this.#requestInfo, this.#requestInit);
|
|
3187
|
+
if (!response.ok) {
|
|
3188
|
+
throw new Error(`Failed to fetch connection configuration: ${response.status} ${response.statusText}`);
|
|
3189
|
+
}
|
|
3190
|
+
const { headers } = response;
|
|
3191
|
+
const host = headers.get(
|
|
3192
|
+
"frontgate-host"
|
|
3193
|
+
/* FRONTGATE_HOST */
|
|
3194
|
+
);
|
|
3195
|
+
const pathPrefix = headers.get(
|
|
3196
|
+
"frontgate-path-prefix"
|
|
3197
|
+
/* FRONTGATE_PATH_PREFIX */
|
|
3198
|
+
);
|
|
3199
|
+
const splitAuthenticationTokenSecondFactor = headers.get(
|
|
3200
|
+
"frontgate-split-authentication-token-second-factor"
|
|
3201
|
+
/* FRONTGATE_SPLIT_AUTHENTICATION_TOKEN_SECOND_FACTOR */
|
|
3202
|
+
);
|
|
3203
|
+
const authenticationType = headers.get(
|
|
3204
|
+
"frontgate-authentication-type"
|
|
3205
|
+
/* FRONTGATE_AUTHENTICATION_TYPE */
|
|
3206
|
+
);
|
|
3207
|
+
const authenticationToken = headers.get(
|
|
3208
|
+
"frontgate-authentication-token"
|
|
3209
|
+
/* FRONTGATE_AUTHENTICATION_TOKEN */
|
|
3210
|
+
);
|
|
3211
|
+
const port = headers.get(
|
|
3212
|
+
"frontgate-websocket-port"
|
|
3213
|
+
/* FRONTGATE_WEBSOCKET_PORT */
|
|
3214
|
+
) ?? "443";
|
|
3215
|
+
const url = `wss://${host}:${port}${pathPrefix ?? ""}/ws`;
|
|
3216
|
+
if (authenticationType === "token" && !authenticationToken) {
|
|
3217
|
+
throw new Error("Authentication token is required for token authentication");
|
|
3218
|
+
}
|
|
3219
|
+
if (authenticationType !== "token" && !splitAuthenticationTokenSecondFactor) {
|
|
3220
|
+
throw new Error("Split authentication token second factor is required");
|
|
3221
|
+
}
|
|
3222
|
+
const protocol = headers.get(
|
|
3223
|
+
"frontgate-websocket-protocol"
|
|
3224
|
+
/* FRONTGATE_WEBSOCKET_PROTOCOL */
|
|
3225
|
+
);
|
|
3226
|
+
if (protocol === "jsjsonc-v2") {
|
|
3227
|
+
this.#shouldCompress = true;
|
|
3228
|
+
} else {
|
|
3229
|
+
this.#shouldCompress = false;
|
|
3230
|
+
}
|
|
3231
|
+
return {
|
|
3232
|
+
url,
|
|
3233
|
+
authtenticationType: authenticationType,
|
|
3234
|
+
authenticationToken,
|
|
3235
|
+
splitAuthenticationTokenSecondFactor
|
|
3236
|
+
};
|
|
3237
|
+
}
|
|
3238
|
+
};
|
|
3239
|
+
};
|
|
3240
|
+
return createExtendedMixinFactory(mixinFetchAuth, {
|
|
3241
|
+
featureName: "FetchAuthWithOptionalCompressor",
|
|
3242
|
+
featureGroups: ["Auth", "Connection"],
|
|
3243
|
+
disabledFeatureGroups: ["Auth", "Connection", "Compression"]
|
|
3244
|
+
});
|
|
3245
|
+
};
|
|
3091
3246
|
const reconnect = (reconnectDelaysInMs) => {
|
|
3092
3247
|
const mixinReconnect = (Base) => {
|
|
3093
3248
|
return class extends Base {
|
|
@@ -4812,6 +4967,7 @@
|
|
|
4812
4967
|
exports2.endpointRequest = endpointRequest;
|
|
4813
4968
|
exports2.endpointSubscriptions = endpointSubscriptions;
|
|
4814
4969
|
exports2.fetchAuth = fetchAuth;
|
|
4970
|
+
exports2.fetchAuthWithOptionalCompressor = fetchAuthWithOptionalCompressor;
|
|
4815
4971
|
exports2.getBytesFromBuffer = getBytesFromBuffer;
|
|
4816
4972
|
exports2.httpProxyRequest = httpProxyRequest;
|
|
4817
4973
|
exports2.levels = levels;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@factset/frontgate-js-sdk",
|
|
3
3
|
"author": "Factset GmbH",
|
|
4
|
-
"version": "7.0
|
|
4
|
+
"version": "7.1.0",
|
|
5
5
|
"description": "Typescript based client to request and subscribe values from mdg2 (frontgate)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "./dist/lib/node/index.js",
|