diff --git a/sony-serialtally/.build-info b/sony-serialtally/.build-info index 4d7eb82f..01da4c77 100644 --- a/sony-serialtally/.build-info +++ b/sony-serialtally/.build-info @@ -1,4 +1,4 @@ MODULE_NAME=sony-serialtally -GIT_REF=v1.2.0 -RUN_URL=https://github.com/bitfocus/companion-bundled-modules/actions/runs/9896976215 -UPDATE_DATE=2024-07-11 +GIT_REF=v1.3.0 +RUN_URL=https://github.com/bitfocus/companion-bundled-modules/actions/runs/11646720890 +UPDATE_DATE=2024-11-02 diff --git a/sony-serialtally/companion/HELP.md b/sony-serialtally/companion/HELP.md index 2ade945c..379574ba 100644 --- a/sony-serialtally/companion/HELP.md +++ b/sony-serialtally/companion/HELP.md @@ -1,16 +1,18 @@ -## Sony XVS +## Sony Serial Tally -This module is for controlling Sony XVS video switchers/vision mixers. +This module is for controlling Sony video switchers/vision mixers that support the XVS serial tally protocol. ### Actions: - XPT M/E - XPT Aux +- Copy Aux - Auto Transition M/E - Key On/Off - Recall Snapshot - Macro Recall/Take - Activate GPI/GPO +- Send Custom Command (if enabled) ### Feedbacks: @@ -20,3 +22,7 @@ This module is for controlling Sony XVS video switchers/vision mixers. ### Variables - M/E: Bus: Current Source +- Source: Name +- Aux: Current Source +- FM: Current Source +- GPI/GPO States diff --git a/sony-serialtally/companion/manifest.json b/sony-serialtally/companion/manifest.json index 11aa95b1..4e63bc88 100644 --- a/sony-serialtally/companion/manifest.json +++ b/sony-serialtally/companion/manifest.json @@ -1 +1 @@ -{"id":"sony-serialtally","name":"Sony Serial Tally","shortname":"sony-switcher","description":"Control Sony video switchers/vision mixers using the serial tally protocol","version":"1.2.0","license":"MIT","repository":"git+https://github.com/bitfocus/companion-module-sony-serialtally.git","bugs":"https://github.com/bitfocus/companion-module-sony-serialtally/issues","maintainers":[{"name":"Joseph Adams","email":"josephdadams@gmail.com"}],"runtime":{"type":"node18","api":"nodejs-ipc","apiVersion":"1.7.1","entrypoint":"../main.js"},"legacyIds":[],"manufacturer":"Sony","products":["XVS 9000/8000/7000/6000","XVS-G1","MLS-X1"],"keywords":["vision mixer","video switcher","sony","serial","tally"]} \ No newline at end of file +{"id":"sony-serialtally","name":"Sony Serial Tally","shortname":"sony-switcher","description":"Control Sony video switchers/vision mixers using the serial tally protocol","version":"1.3.0","license":"MIT","repository":"git+https://github.com/bitfocus/companion-module-sony-serialtally.git","bugs":"https://github.com/bitfocus/companion-module-sony-serialtally/issues","maintainers":[{"name":"Joseph Adams","email":"josephdadams@gmail.com"}],"runtime":{"type":"node18","api":"nodejs-ipc","apiVersion":"1.7.1","entrypoint":"../main.js"},"legacyIds":[],"manufacturer":"Sony","products":["XVS 9000/8000/7000/6000","XVS-G1","MLS-X1"],"keywords":["vision mixer","video switcher","sony","serial","tally"]} \ No newline at end of file diff --git a/sony-serialtally/main.js b/sony-serialtally/main.js index 31e7a166..c611e670 100644 --- a/sony-serialtally/main.js +++ b/sony-serialtally/main.js @@ -1 +1 @@ -(()=>{var e={7169:(e,t,n)=>{"use strict";const i=n(2017);i.code='require("ajv/dist/runtime/equal").default',t.A=i},2581:(e,t,n)=>{"use strict";n.d(t,{l:()=>r});var i=n(6588),s=n(1763),o=n(8560);function r(){(0,s.U)(),(0,o.wD)()&&function(){const t=(0,i.EU)();if(!t.__SENTRY__)return;const n={mongodb:()=>new((0,o.fj)(e,"./node/integrations/mongo").Mongo),mongoose:()=>new((0,o.fj)(e,"./node/integrations/mongo").Mongo),mysql:()=>new((0,o.fj)(e,"./node/integrations/mysql").Mysql),pg:()=>new((0,o.fj)(e,"./node/integrations/postgres").Postgres)},s=Object.keys(n).filter((e=>!!(0,o.Vw)(e))).map((e=>{try{return n[e]()}catch(e){return}})).filter((e=>e));s.length>0&&(t.__SENTRY__.integrations=[...t.__SENTRY__.integrations||[],...s])}()}e=n.hmd(e)},7765:(e,t,n)=>{"use strict";n.d(t,{U:()=>i});const i="production"},7022:(e,t,n)=>{"use strict";n.d(t,{T:()=>i});const i="undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__},9071:(e,t,n)=>{"use strict";n.d(t,{KU:()=>o,o5:()=>r,v4:()=>s});var i=n(6588);function s(...e){const t=(0,i.BF)();if(2===e.length){const[n,i]=e;return n?t.withScope((()=>(t.getStackTop().scope=n,i(n)))):t.withScope(i)}return t.withScope(e[0])}function o(){return(0,i.BF)().getClient()}function r(){return(0,i.BF)().getScope()}},6588:(e,t,n)=>{"use strict";n.d(t,{BF:()=>f,rm:()=>V,EU:()=>A,fx:()=>v});var i,s=n(138),o=n(4902),r=n(7567),a=n(6202),c=n(2231),l=n(7765),g=n(7022);!function(e){e[e.PENDING=0]="PENDING",e[e.RESOLVED=1]="RESOLVED",e[e.REJECTED=2]="REJECTED"}(i||(i={}));class d{constructor(e){d.prototype.__init.call(this),d.prototype.__init2.call(this),d.prototype.__init3.call(this),d.prototype.__init4.call(this),this._state=i.PENDING,this._handlers=[];try{e(this._resolve,this._reject)}catch(e){this._reject(e)}}then(e,t){return new d(((n,i)=>{this._handlers.push([!1,t=>{if(e)try{n(e(t))}catch(e){i(e)}else n(t)},e=>{if(t)try{n(t(e))}catch(e){i(e)}else i(e)}]),this._executeHandlers()}))}catch(e){return this.then((e=>e),e)}finally(e){return new d(((t,n)=>{let i,s;return this.then((t=>{s=!1,i=t,e&&e()}),(t=>{s=!0,i=t,e&&e()})).then((()=>{s?n(i):t(i)}))}))}__init(){this._resolve=e=>{this._setResult(i.RESOLVED,e)}}__init2(){this._reject=e=>{this._setResult(i.REJECTED,e)}}__init3(){this._setResult=(e,t)=>{this._state===i.PENDING&&((0,s.Qg)(t)?t.then(this._resolve,this._reject):(this._state=e,this._value=t,this._executeHandlers()))}}__init4(){this._executeHandlers=()=>{if(this._state===i.PENDING)return;const e=this._handlers.slice();this._handlers=[],e.forEach((e=>{e[0]||(this._state===i.RESOLVED&&e[1](this._value),this._state===i.REJECTED&&e[2](this._value),e[0]=!0)}))}}}function u(e,t,n,i=0){return new d(((o,r)=>{const c=e[i];if(null===t||"function"!=typeof c)o(t);else{const l=c({...t},n);g.T&&c.id&&null===l&&a.vF.log(`Event processor "${c.id}" dropped event`),(0,s.Qg)(l)?l.then((t=>u(e,t,n,i+1).then(o))).then(null,r):u(e,l,n,i+1).then(o).then(null,r)}}))}var b=n(1041);function I(e,t={}){if(t.user&&(!e.ipAddress&&t.user.ip_address&&(e.ipAddress=t.user.ip_address),e.did||t.did||(e.did=t.user.id||t.user.email||t.user.username)),e.timestamp=t.timestamp||(0,r.zf)(),t.abnormal_mechanism&&(e.abnormal_mechanism=t.abnormal_mechanism),t.ignoreDuration&&(e.ignoreDuration=t.ignoreDuration),t.sid&&(e.sid=32===t.sid.length?t.sid:(0,o.eJ)()),void 0!==t.init&&(e.init=t.init),!e.did&&t.did&&(e.did=`${t.did}`),"number"==typeof t.started&&(e.started=t.started),e.ignoreDuration)e.duration=void 0;else if("number"==typeof t.duration)e.duration=t.duration;else{const t=e.timestamp-e.started;e.duration=t>=0?t:0}t.release&&(e.release=t.release),t.environment&&(e.environment=t.environment),!e.ipAddress&&t.ipAddress&&(e.ipAddress=t.ipAddress),!e.userAgent&&t.userAgent&&(e.userAgent=t.userAgent),"number"==typeof t.errors&&(e.errors=t.errors),t.status&&(e.status=t.status)}var p=n(9738),C=n(9266),h=n(5895);class m{constructor(){this._notifyingListeners=!1,this._scopeListeners=[],this._eventProcessors=[],this._breadcrumbs=[],this._attachments=[],this._user={},this._tags={},this._extra={},this._contexts={},this._sdkProcessingMetadata={},this._propagationContext=y()}static clone(e){return e?e.clone():new m}clone(){const e=new m;return e._breadcrumbs=[...this._breadcrumbs],e._tags={...this._tags},e._extra={...this._extra},e._contexts={...this._contexts},e._user=this._user,e._level=this._level,e._span=this._span,e._session=this._session,e._transactionName=this._transactionName,e._fingerprint=this._fingerprint,e._eventProcessors=[...this._eventProcessors],e._requestSession=this._requestSession,e._attachments=[...this._attachments],e._sdkProcessingMetadata={...this._sdkProcessingMetadata},e._propagationContext={...this._propagationContext},e._client=this._client,e}setClient(e){this._client=e}getClient(){return this._client}addScopeListener(e){this._scopeListeners.push(e)}addEventProcessor(e){return this._eventProcessors.push(e),this}setUser(e){return this._user=e||{email:void 0,id:void 0,ip_address:void 0,segment:void 0,username:void 0},this._session&&I(this._session,{user:e}),this._notifyScopeListeners(),this}getUser(){return this._user}getRequestSession(){return this._requestSession}setRequestSession(e){return this._requestSession=e,this}setTags(e){return this._tags={...this._tags,...e},this._notifyScopeListeners(),this}setTag(e,t){return this._tags={...this._tags,[e]:t},this._notifyScopeListeners(),this}setExtras(e){return this._extra={...this._extra,...e},this._notifyScopeListeners(),this}setExtra(e,t){return this._extra={...this._extra,[e]:t},this._notifyScopeListeners(),this}setFingerprint(e){return this._fingerprint=e,this._notifyScopeListeners(),this}setLevel(e){return this._level=e,this._notifyScopeListeners(),this}setTransactionName(e){return this._transactionName=e,this._notifyScopeListeners(),this}setContext(e,t){return null===t?delete this._contexts[e]:this._contexts[e]=t,this._notifyScopeListeners(),this}setSpan(e){return this._span=e,this._notifyScopeListeners(),this}getSpan(){return this._span}getTransaction(){const e=this._span;return e&&e.transaction}setSession(e){return e?this._session=e:delete this._session,this._notifyScopeListeners(),this}getSession(){return this._session}update(e){if(!e)return this;const t="function"==typeof e?e(this):e;if(t instanceof m){const e=t.getScopeData();this._tags={...this._tags,...e.tags},this._extra={...this._extra,...e.extra},this._contexts={...this._contexts,...e.contexts},e.user&&Object.keys(e.user).length&&(this._user=e.user),e.level&&(this._level=e.level),e.fingerprint.length&&(this._fingerprint=e.fingerprint),t.getRequestSession()&&(this._requestSession=t.getRequestSession()),e.propagationContext&&(this._propagationContext=e.propagationContext)}else if((0,s.Qd)(t)){const t=e;this._tags={...this._tags,...t.tags},this._extra={...this._extra,...t.extra},this._contexts={...this._contexts,...t.contexts},t.user&&(this._user=t.user),t.level&&(this._level=t.level),t.fingerprint&&(this._fingerprint=t.fingerprint),t.requestSession&&(this._requestSession=t.requestSession),t.propagationContext&&(this._propagationContext=t.propagationContext)}return this}clear(){return this._breadcrumbs=[],this._tags={},this._extra={},this._user={},this._contexts={},this._level=void 0,this._transactionName=void 0,this._fingerprint=void 0,this._requestSession=void 0,this._span=void 0,this._session=void 0,this._notifyScopeListeners(),this._attachments=[],this._propagationContext=y(),this}addBreadcrumb(e,t){const n="number"==typeof t?t:100;if(n<=0)return this;const i={timestamp:(0,r.lu)(),...e},s=this._breadcrumbs;return s.push(i),this._breadcrumbs=s.length>n?s.slice(-n):s,this._notifyScopeListeners(),this}getLastBreadcrumb(){return this._breadcrumbs[this._breadcrumbs.length-1]}clearBreadcrumbs(){return this._breadcrumbs=[],this._notifyScopeListeners(),this}addAttachment(e){return this._attachments.push(e),this}getAttachments(){return this.getScopeData().attachments}clearAttachments(){return this._attachments=[],this}getScopeData(){const{_breadcrumbs:e,_attachments:t,_contexts:n,_tags:i,_extra:s,_user:o,_level:r,_fingerprint:a,_eventProcessors:c,_propagationContext:l,_sdkProcessingMetadata:g,_transactionName:d,_span:u}=this;return{breadcrumbs:e,attachments:t,contexts:n,tags:i,extra:s,user:o,level:r,fingerprint:a||[],eventProcessors:c,propagationContext:l,sdkProcessingMetadata:g,transactionName:d,span:u}}applyToEvent(e,t={},n=[]){return function(e,t){const{fingerprint:n,span:i,breadcrumbs:s,sdkProcessingMetadata:r}=t;!function(e,t){const{extra:n,tags:i,user:s,contexts:o,level:r,transactionName:a}=t,c=(0,b.Ce)(n);c&&Object.keys(c).length&&(e.extra={...c,...e.extra});const l=(0,b.Ce)(i);l&&Object.keys(l).length&&(e.tags={...l,...e.tags});const g=(0,b.Ce)(s);g&&Object.keys(g).length&&(e.user={...g,...e.user});const d=(0,b.Ce)(o);d&&Object.keys(d).length&&(e.contexts={...d,...e.contexts}),r&&(e.level=r),a&&(e.transaction=a)}(e,t),i&&function(e,t){e.contexts={trace:(0,h.kX)(t),...e.contexts};const n=(0,C.z)(t);if(n){e.sdkProcessingMetadata={dynamicSamplingContext:(0,p.k)(t),...e.sdkProcessingMetadata};const i=(0,h.et)(n).description;i&&(e.tags={transaction:i,...e.tags})}}(e,i),function(e,t){e.fingerprint=e.fingerprint?(0,o.k9)(e.fingerprint):[],t&&(e.fingerprint=e.fingerprint.concat(t)),e.fingerprint&&!e.fingerprint.length&&delete e.fingerprint}(e,n),function(e,t){const n=[...e.breadcrumbs||[],...t];e.breadcrumbs=n.length?n:void 0}(e,s),function(e,t){e.sdkProcessingMetadata={...e.sdkProcessingMetadata,...t}}(e,r)}(e,this.getScopeData()),u([...n,...(0,c.BY)("globalEventProcessors",(()=>[])),...this._eventProcessors],e,t)}setSDKProcessingMetadata(e){return this._sdkProcessingMetadata={...this._sdkProcessingMetadata,...e},this}setPropagationContext(e){return this._propagationContext=e,this}getPropagationContext(){return this._propagationContext}captureException(e,t){const n=t&&t.event_id?t.event_id:(0,o.eJ)();if(!this._client)return a.vF.warn("No client configured on scope - will not capture exception!"),n;const i=new Error("Sentry syntheticException");return this._client.captureException(e,{originalException:e,syntheticException:i,...t,event_id:n},this),n}captureMessage(e,t,n){const i=n&&n.event_id?n.event_id:(0,o.eJ)();if(!this._client)return a.vF.warn("No client configured on scope - will not capture message!"),i;const s=new Error(e);return this._client.captureMessage(e,t,{originalException:e,syntheticException:s,...n,event_id:i},this),i}captureEvent(e,t){const n=t&&t.event_id?t.event_id:(0,o.eJ)();return this._client?(this._client.captureEvent(e,{...t,event_id:n},this),n):(a.vF.warn("No client configured on scope - will not capture event!"),n)}_notifyScopeListeners(){this._notifyingListeners||(this._notifyingListeners=!0,this._scopeListeners.forEach((e=>{e(this)})),this._notifyingListeners=!1)}}function y(){return{traceId:(0,o.eJ)(),spanId:(0,o.eJ)().substring(16)}}const Z=parseFloat("7.114.0"),G=100;class B{constructor(e,t,n,i=Z){let s,o;this._version=i,t?s=t:(s=new m,s.setClient(e)),n?o=n:(o=new m,o.setClient(e)),this._stack=[{scope:s}],e&&this.bindClient(e),this._isolationScope=o}isOlderThan(e){return this._version(this.popScope(),e)),(e=>{throw this.popScope(),e})):(this.popScope(),n)}getClient(){return this.getStackTop().client}getScope(){return this.getStackTop().scope}getIsolationScope(){return this._isolationScope}getStack(){return this._stack}getStackTop(){return this._stack[this._stack.length-1]}captureException(e,t){const n=this._lastEventId=t&&t.event_id?t.event_id:(0,o.eJ)(),i=new Error("Sentry syntheticException");return this.getScope().captureException(e,{originalException:e,syntheticException:i,...t,event_id:n}),n}captureMessage(e,t,n){const i=this._lastEventId=n&&n.event_id?n.event_id:(0,o.eJ)(),s=new Error(e);return this.getScope().captureMessage(e,t,{originalException:e,syntheticException:s,...n,event_id:i}),i}captureEvent(e,t){const n=t&&t.event_id?t.event_id:(0,o.eJ)();return e.type||(this._lastEventId=n),this.getScope().captureEvent(e,{...t,event_id:n}),n}lastEventId(){return this._lastEventId}addBreadcrumb(e,t){const{scope:n,client:i}=this.getStackTop();if(!i)return;const{beforeBreadcrumb:s=null,maxBreadcrumbs:o=G}=i.getOptions&&i.getOptions()||{};if(o<=0)return;const c={timestamp:(0,r.lu)(),...e},l=s?(0,a.pq)((()=>s(c,t))):c;null!==l&&(i.emit&&i.emit("beforeAddBreadcrumb",l,t),n.addBreadcrumb(l,o))}setUser(e){this.getScope().setUser(e),this.getIsolationScope().setUser(e)}setTags(e){this.getScope().setTags(e),this.getIsolationScope().setTags(e)}setExtras(e){this.getScope().setExtras(e),this.getIsolationScope().setExtras(e)}setTag(e,t){this.getScope().setTag(e,t),this.getIsolationScope().setTag(e,t)}setExtra(e,t){this.getScope().setExtra(e,t),this.getIsolationScope().setExtra(e,t)}setContext(e,t){this.getScope().setContext(e,t),this.getIsolationScope().setContext(e,t)}configureScope(e){const{scope:t,client:n}=this.getStackTop();n&&e(t)}run(e){const t=W(this);try{e(this)}finally{W(t)}}getIntegration(e){const t=this.getClient();if(!t)return null;try{return t.getIntegration(e)}catch(t){return g.T&&a.vF.warn(`Cannot retrieve integration ${e.id} from the current Hub`),null}}startTransaction(e,t){const n=this._callExtensionMethod("startTransaction",e,t);return g.T&&!n&&(this.getClient()?a.vF.warn("Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init':\nSentry.addTracingExtensions();\nSentry.init({...});\n"):a.vF.warn("Tracing extension 'startTransaction' is missing. You should 'init' the SDK before calling 'startTransaction'")),n}traceHeaders(){return this._callExtensionMethod("traceHeaders")}captureSession(e=!1){if(e)return this.endSession();this._sendSessionUpdate()}endSession(){const e=this.getStackTop().scope,t=e.getSession();t&&function(e,t){let n={};"ok"===e.status&&(n={status:"exited"}),I(e,n)}(t),this._sendSessionUpdate(),e.setSession()}startSession(e){const{scope:t,client:n}=this.getStackTop(),{release:i,environment:s=l.U}=n&&n.getOptions()||{},{userAgent:a}=c.OW.navigator||{},g=function(e){const t=(0,r.zf)(),n={sid:(0,o.eJ)(),init:!0,timestamp:t,started:t,duration:0,status:"ok",errors:0,ignoreDuration:!1,toJSON:()=>function(e){return(0,b.Ce)({sid:`${e.sid}`,init:e.init,started:new Date(1e3*e.started).toISOString(),timestamp:new Date(1e3*e.timestamp).toISOString(),status:e.status,errors:e.errors,did:"number"==typeof e.did||"string"==typeof e.did?`${e.did}`:void 0,duration:e.duration,abnormal_mechanism:e.abnormal_mechanism,attrs:{release:e.release,environment:e.environment,ip_address:e.ipAddress,user_agent:e.userAgent}})}(n)};return e&&I(n,e),n}({release:i,environment:s,user:t.getUser(),...a&&{userAgent:a},...e}),d=t.getSession&&t.getSession();return d&&"ok"===d.status&&I(d,{status:"exited"}),this.endSession(),t.setSession(g),g}shouldSendDefaultPii(){const e=this.getClient(),t=e&&e.getOptions();return Boolean(t&&t.sendDefaultPii)}_sendSessionUpdate(){const{scope:e,client:t}=this.getStackTop(),n=e.getSession();n&&t&&t.captureSession&&t.captureSession(n)}_callExtensionMethod(e,...t){const n=A().__SENTRY__;if(n&&n.extensions&&"function"==typeof n.extensions[e])return n.extensions[e].apply(this,t);g.T&&a.vF.warn(`Extension method ${e} couldn't be found, doing nothing.`)}}function A(){return c.OW.__SENTRY__=c.OW.__SENTRY__||{extensions:{},hub:void 0},c.OW}function W(e){const t=A(),n=R(t);return Y(t,e),n}function f(){const e=A();if(e.__SENTRY__&&e.__SENTRY__.acs){const t=e.__SENTRY__.acs.getCurrentHub();if(t)return t}return function(e=A()){return t=e,!!(t&&t.__SENTRY__&&t.__SENTRY__.hub)&&!R(e).isOlderThan(Z)||Y(e,new B),R(e);var t}(e)}function V(){return f().getIsolationScope()}function v(e,t={}){const n=A();return n.__SENTRY__&&n.__SENTRY__.acs?n.__SENTRY__.acs.runWithAsyncContext(e,t):e()}function R(e){return(0,c.BY)("hub",(()=>new B),e)}function Y(e,t){return!!e&&((e.__SENTRY__=e.__SENTRY__||{}).hub=t,!0)}},741:(e,t,n)=>{"use strict";n.d(t,{g:()=>o});var i=n(1041);let s;function o(e){const t=function(e){return s?s.get(e):void 0}(e);if(!t)return;const n={};for(const[,[e,s]]of t)n[e]||(n[e]=[]),n[e].push((0,i.Ce)(s));return n}},5071:(e,t,n)=>{"use strict";n.d(t,{E1:()=>a,JD:()=>r,i_:()=>i,sy:()=>s,uT:()=>o});const i="sentry.source",s="sentry.sample_rate",o="sentry.op",r="sentry.origin",a="profile_id"},9738:(e,t,n)=>{"use strict";n.d(t,{k:()=>l,l:()=>c});var i=n(1041),s=n(7765),o=n(9071),r=n(9266),a=n(5895);function c(e,t,n){const o=t.getOptions(),{publicKey:r}=t.getDsn()||{},{segment:a}=n&&n.getUser()||{},c=(0,i.Ce)({environment:o.environment||s.U,release:o.release,user_segment:a,public_key:r,trace_id:e});return t.emit&&t.emit("createDsc",c),c}function l(e){const t=(0,o.KU)();if(!t)return{};const n=c((0,a.et)(e).trace_id||"",t,(0,o.o5)()),i=(0,r.z)(e);if(!i)return n;const s=i&&i._frozenDynamicSamplingContext;if(s)return s;const{sampleRate:l,source:g}=i.metadata;null!=l&&(n.sample_rate=`${l}`);const d=(0,a.et)(i);return g&&"url"!==g&&(n.transaction=d.description),n.sampled=String((0,a.pK)(i)),t.emit&&t.emit("createDsc",n),n}},1763:(e,t,n)=>{"use strict";n.d(t,{U:()=>B,p:()=>G});var i=n(6202),s=n(7022),o=n(6588),r=n(5895),a=n(2231),c=n(6768);let l=null;function g(){l=a.OW.onerror,a.OW.onerror=function(e,t,n,i,s){const o={column:i,error:s,line:n,msg:e,url:t};return(0,c.aj)("error",o),!(!l||l.__SENTRY_LOADER__)&&l.apply(this,arguments)},a.OW.onerror.__SENTRY_INSTRUMENTED__=!0}let d=null;function u(){d=a.OW.onunhandledrejection,a.OW.onunhandledrejection=function(e){const t=e;return(0,c.aj)("unhandledrejection",t),!(d&&!d.__SENTRY_LOADER__)||d.apply(this,arguments)},a.OW.onunhandledrejection.__SENTRY_INSTRUMENTED__=!0}var b=n(1692);let I=!1;function p(){const e=(0,b.Z7)();if(e){const t="internal_error";s.T&&i.vF.log(`[Tracing] Transaction: ${t} -> Global error occured`),e.setStatus(t)}}p.tag="sentry_tracingErrorCallback";var C=n(683),h=n(6056),m=n(9049);function y(){const e=this.getScope().getSpan();return e?{"sentry-trace":(0,r.Qh)(e)}:{}}function Z(e,t){const n=this.getClient(),o=n&&n.getOptions()||{},r=o.instrumenter||"sentry",a=e.instrumenter||"sentry";r!==a&&(s.T&&i.vF.error(`A transaction was started with instrumenter=\`${a}\`, but the SDK is configured with the \`${r}\` instrumenter.\nThe transaction will not be sampled. Please use the ${r} instrumentation to start transactions.`),e.sampled=!1);let c=new m.Z(e,this);return c=(0,h.T)(c,o,{name:e.name,parentSampled:e.parentSampled,transactionContext:e,attributes:{...e.data,...e.attributes},...t}),c.isRecording()&&c.initSpanRecorder(o._experiments&&o._experiments.maxSpans),n&&n.emit&&n.emit("startTransaction",c),c}function G(e,t,n,i,s,o,r,a=!1){const c=e.getClient(),l=c&&c.getOptions()||{};let g=new C.zX(t,e,n,i,r,s,a);return g=(0,h.T)(g,l,{name:t.name,parentSampled:t.parentSampled,transactionContext:t,attributes:{...t.data,...t.attributes},...o}),g.isRecording()&&g.initSpanRecorder(l._experiments&&l._experiments.maxSpans),c&&c.emit&&c.emit("startTransaction",g),g}function B(){const e=(0,o.EU)();e.__SENTRY__&&(e.__SENTRY__.extensions=e.__SENTRY__.extensions||{},e.__SENTRY__.extensions.startTransaction||(e.__SENTRY__.extensions.startTransaction=Z),e.__SENTRY__.extensions.traceHeaders||(e.__SENTRY__.extensions.traceHeaders=y),I||(I=!0,function(e){const t="error";(0,c.s5)(t,e),(0,c.AS)(t,g)}(p),function(e){const t="unhandledrejection";(0,c.s5)(t,e),(0,c.AS)(t,u)}(p)))}},683:(e,t,n)=>{"use strict";n.d(t,{Cq:()=>l,zX:()=>u});var i=n(6202),s=n(7567),o=n(7022),r=n(5895),a=n(7037),c=n(9049);const l={idleTimeout:1e3,finalTimeout:3e4,heartbeatInterval:5e3},g=["heartbeatFailed","idleTimeout","documentHidden","finalTimeout","externalFinish","cancelled"];class d extends a.l{constructor(e,t,n,i){super(i),this._pushActivity=e,this._popActivity=t,this.transactionSpanId=n}add(e){if(e.spanContext().spanId!==this.transactionSpanId){const t=e.end;e.end=(...n)=>(this._popActivity(e.spanContext().spanId),t.apply(e,n)),void 0===(0,r.et)(e).timestamp&&this._pushActivity(e.spanContext().spanId)}super.add(e)}}class u extends c.Z{constructor(e,t,n=l.idleTimeout,s=l.finalTimeout,r=l.heartbeatInterval,a=!1,c=!1){super(e,t),this._idleHub=t,this._idleTimeout=n,this._finalTimeout=s,this._heartbeatInterval=r,this._onScope=a,this.activities={},this._heartbeatCounter=0,this._finished=!1,this._idleTimeoutCanceledPermanently=!1,this._beforeFinishCallbacks=[],this._finishReason=g[4],this._autoFinishAllowed=!c,a&&(o.T&&i.vF.log(`Setting idle transaction on scope. Span ID: ${this.spanContext().spanId}`),t.getScope().setSpan(this)),c||this._restartIdleTimeout(),setTimeout((()=>{this._finished||(this.setStatus("deadline_exceeded"),this._finishReason=g[3],this.end())}),this._finalTimeout)}end(e){const t=(0,r.cI)(e);if(this._finished=!0,this.activities={},"ui.action.click"===this.op&&this.setAttribute("finishReason",this._finishReason),this.spanRecorder){o.T&&i.vF.log("[Tracing] finishing IdleTransaction",new Date(1e3*t).toISOString(),this.op);for(const e of this._beforeFinishCallbacks)e(this,t);this.spanRecorder.spans=this.spanRecorder.spans.filter((e=>{if(e.spanContext().spanId===this.spanContext().spanId)return!0;(0,r.et)(e).timestamp||(e.setStatus("cancelled"),e.end(t),o.T&&i.vF.log("[Tracing] cancelling span since transaction ended early",JSON.stringify(e,void 0,2)));const{start_timestamp:n,timestamp:s}=(0,r.et)(e),a=n&&n{this._finished||this._pushActivity(e)},n=e=>{this._finished||this._popActivity(e)};this.spanRecorder=new d(t,n,this.spanContext().spanId,e),o.T&&i.vF.log("Starting heartbeat"),this._pingHeartbeat()}this.spanRecorder.add(this)}cancelIdleTimeout(e,{restartOnChildSpanChange:t}={restartOnChildSpanChange:!0}){this._idleTimeoutCanceledPermanently=!1===t,this._idleTimeoutID&&(clearTimeout(this._idleTimeoutID),this._idleTimeoutID=void 0,0===Object.keys(this.activities).length&&this._idleTimeoutCanceledPermanently&&(this._finishReason=g[5],this.end(e)))}setFinishReason(e){this._finishReason=e}sendAutoFinishSignal(){this._autoFinishAllowed||(o.T&&i.vF.log("[Tracing] Received finish signal for idle transaction."),this._restartIdleTimeout(),this._autoFinishAllowed=!0)}_restartIdleTimeout(e){this.cancelIdleTimeout(),this._idleTimeoutID=setTimeout((()=>{this._finished||0!==Object.keys(this.activities).length||(this._finishReason=g[1],this.end(e))}),this._idleTimeout)}_pushActivity(e){this.cancelIdleTimeout(void 0,{restartOnChildSpanChange:!this._idleTimeoutCanceledPermanently}),o.T&&i.vF.log(`[Tracing] pushActivity: ${e}`),this.activities[e]=!0,o.T&&i.vF.log("[Tracing] new activities count",Object.keys(this.activities).length)}_popActivity(e){if(this.activities[e]&&(o.T&&i.vF.log(`[Tracing] popActivity ${e}`),delete this.activities[e],o.T&&i.vF.log("[Tracing] new activities count",Object.keys(this.activities).length)),0===Object.keys(this.activities).length){const e=(0,s.zf)();this._idleTimeoutCanceledPermanently?this._autoFinishAllowed&&(this._finishReason=g[5],this.end(e)):this._restartIdleTimeout(e+this._idleTimeout/1e3)}}_beat(){if(this._finished)return;const e=Object.keys(this.activities).join("");e===this._prevHeartbeatString?this._heartbeatCounter++:this._heartbeatCounter=1,this._prevHeartbeatString=e,this._heartbeatCounter>=3?this._autoFinishAllowed&&(o.T&&i.vF.log("[Tracing] Transaction finished because of no change for 3 heart beats"),this.setStatus("deadline_exceeded"),this._finishReason=g[0],this.end()):this._pingHeartbeat()}_pingHeartbeat(){o.T&&i.vF.log(`pinging Heartbeat -> current counter: ${this._heartbeatCounter}`),setTimeout((()=>{this._beat()}),this._heartbeatInterval)}}},6056:(e,t,n)=>{"use strict";n.d(t,{T:()=>l,v:()=>g});var i=n(6202),s=n(138),o=n(7022),r=n(5071),a=n(5177),c=n(5895);function l(e,t,n){if(!(0,a.w)(t))return e.sampled=!1,e;if(void 0!==e.sampled)return e.setAttribute(r.sy,Number(e.sampled)),e;let s;return"function"==typeof t.tracesSampler?(s=t.tracesSampler(n),e.setAttribute(r.sy,Number(s))):void 0!==n.parentSampled?s=n.parentSampled:void 0!==t.tracesSampleRate?(s=t.tracesSampleRate,e.setAttribute(r.sy,Number(s))):(s=1,e.setAttribute(r.sy,s)),g(s)?s?(e.sampled=Math.random()1)||(o.T&&i.vF.warn(`[Tracing] Given sample rate is invalid. Sample rate must be between 0 and 1. Got ${e}.`),!1)}},7037:(e,t,n)=>{"use strict";n.d(t,{L:()=>I,l:()=>b});var i=n(4902),s=n(7567),o=n(6202),r=n(1041),a=n(7022),c=n(741),l=n(5071),g=n(9266),d=n(5895),u=n(4131);class b{constructor(e=1e3){this._maxlen=e,this.spans=[]}add(e){this.spans.length>this._maxlen?e.spanRecorder=void 0:this.spans.push(e)}}class I{constructor(e={}){this._traceId=e.traceId||(0,i.eJ)(),this._spanId=e.spanId||(0,i.eJ)().substring(16),this._startTime=e.startTimestamp||(0,s.zf)(),this.tags=e.tags?{...e.tags}:{},this.data=e.data?{...e.data}:{},this.instrumenter=e.instrumenter||"sentry",this._attributes={},this.setAttributes({[l.JD]:e.origin||"manual",[l.uT]:e.op,...e.attributes}),this._name=e.name||e.description,e.parentSpanId&&(this._parentSpanId=e.parentSpanId),"sampled"in e&&(this._sampled=e.sampled),e.status&&(this._status=e.status),e.endTimestamp&&(this._endTime=e.endTimestamp),void 0!==e.exclusiveTime&&(this._exclusiveTime=e.exclusiveTime),this._measurements=e.measurements?{...e.measurements}:{}}get name(){return this._name||""}set name(e){this.updateName(e)}get description(){return this._name}set description(e){this._name=e}get traceId(){return this._traceId}set traceId(e){this._traceId=e}get spanId(){return this._spanId}set spanId(e){this._spanId=e}set parentSpanId(e){this._parentSpanId=e}get parentSpanId(){return this._parentSpanId}get sampled(){return this._sampled}set sampled(e){this._sampled=e}get attributes(){return this._attributes}set attributes(e){this._attributes=e}get startTimestamp(){return this._startTime}set startTimestamp(e){this._startTime=e}get endTimestamp(){return this._endTime}set endTimestamp(e){this._endTime=e}get status(){return this._status}set status(e){this._status=e}get op(){return this._attributes[l.uT]}set op(e){this.setAttribute(l.uT,e)}get origin(){return this._attributes[l.JD]}set origin(e){this.setAttribute(l.JD,e)}spanContext(){const{_spanId:e,_traceId:t,_sampled:n}=this;return{spanId:e,traceId:t,traceFlags:n?d.aO:d.CC}}startChild(e){const t=new I({...e,parentSpanId:this._spanId,sampled:this._sampled,traceId:this._traceId});t.spanRecorder=this.spanRecorder,t.spanRecorder&&t.spanRecorder.add(t);const n=(0,g.z)(this);if(t.transaction=n,a.T&&n){const i=`[Tracing] Starting '${e&&e.op||"< unknown op >"}' span on transaction '${(0,d.et)(t).description||"< unknown name >"}' (${n.spanContext().spanId}).`;o.vF.log(i),this._logMessage=i}return t}setTag(e,t){return this.tags={...this.tags,[e]:t},this}setData(e,t){return this.data={...this.data,[e]:t},this}setAttribute(e,t){void 0===t?delete this._attributes[e]:this._attributes[e]=t}setAttributes(e){Object.keys(e).forEach((t=>this.setAttribute(t,e[t])))}setStatus(e){return this._status=e,this}setHttpStatus(e){return(0,u.N8)(this,e),this}setName(e){this.updateName(e)}updateName(e){return this._name=e,this}isSuccess(){return"ok"===this._status}finish(e){return this.end(e)}end(e){if(this._endTime)return;const t=(0,g.z)(this);if(a.T&&t&&t.spanContext().spanId!==this._spanId){const e=this._logMessage;e&&o.vF.log(e.replace("Starting","Finishing"))}this._endTime=(0,d.cI)(e)}toTraceparent(){return(0,d.Qh)(this)}toContext(){return(0,r.Ce)({data:this._getData(),description:this._name,endTimestamp:this._endTime,op:this.op,parentSpanId:this._parentSpanId,sampled:this._sampled,spanId:this._spanId,startTimestamp:this._startTime,status:this._status,tags:this.tags,traceId:this._traceId})}updateWithContext(e){return this.data=e.data||{},this._name=e.name||e.description,this._endTime=e.endTimestamp,this.op=e.op,this._parentSpanId=e.parentSpanId,this._sampled=e.sampled,this._spanId=e.spanId||this._spanId,this._startTime=e.startTimestamp||this._startTime,this._status=e.status,this.tags=e.tags||{},this._traceId=e.traceId||this._traceId,this}getTraceContext(){return(0,d.kX)(this)}getSpanJSON(){return(0,r.Ce)({data:this._getData(),description:this._name,op:this._attributes[l.uT],parent_span_id:this._parentSpanId,span_id:this._spanId,start_timestamp:this._startTime,status:this._status,tags:Object.keys(this.tags).length>0?this.tags:void 0,timestamp:this._endTime,trace_id:this._traceId,origin:this._attributes[l.JD],_metrics_summary:(0,c.g)(this),profile_id:this._attributes[l.E1],exclusive_time:this._exclusiveTime,measurements:Object.keys(this._measurements).length>0?this._measurements:void 0})}isRecording(){return!this._endTime&&!!this._sampled}toJSON(){return this.getSpanJSON()}_getData(){const{data:e,_attributes:t}=this,n=Object.keys(e).length>0,i=Object.keys(t).length>0;if(n||i)return n&&i?{...e,...t}:n?e:t}}},4131:(e,t,n)=>{"use strict";var i;function s(e){if(e<400&&e>=100)return"ok";if(e>=400&&e<500)switch(e){case 401:return"unauthenticated";case 403:return"permission_denied";case 404:return"not_found";case 409:return"already_exists";case 413:return"failed_precondition";case 429:return"resource_exhausted";default:return"invalid_argument"}if(e>=500&&e<600)switch(e){case 501:return"unimplemented";case 503:return"unavailable";case 504:return"deadline_exceeded";default:return"internal_error"}return"unknown_error"}n.d(t,{Fp:()=>i,N8:()=>r,o6:()=>o}),function(e){e.Ok="ok",e.DeadlineExceeded="deadline_exceeded",e.Unauthenticated="unauthenticated",e.PermissionDenied="permission_denied",e.NotFound="not_found",e.ResourceExhausted="resource_exhausted",e.InvalidArgument="invalid_argument",e.Unimplemented="unimplemented",e.Unavailable="unavailable",e.InternalError="internal_error",e.UnknownError="unknown_error",e.Cancelled="cancelled",e.AlreadyExists="already_exists",e.FailedPrecondition="failed_precondition",e.Aborted="aborted",e.OutOfRange="out_of_range",e.DataLoss="data_loss"}(i||(i={}));const o=s;function r(e,t){e.setTag("http.status_code",String(t)),e.setData("http.response.status_code",t);const n=s(t);"unknown_error"!==n&&e.setStatus(n)}},9589:(e,t,n)=>{"use strict";n.d(t,{Lb:()=>C,Uk:()=>d,Lk:()=>g});var i=n(1041),s=n(6588),o=n(5895),r=n(9738),a=n(9071),c=n(138);var l=n(5177);function g(e,t){const n=b(e);return(0,s.fx)((()=>(0,a.v4)(e.scope,(i=>{const r=(0,s.BF)(),a=i.getSpan(),l=e.onlyIfParent&&!a?void 0:u(r,{parentSpan:a,spanContext:n,forceTransaction:e.forceTransaction,scope:i});return function(e,t,n=()=>{}){let i;try{i=e()}catch(e){throw t(e),n(),e}return function(e,t,n){return(0,c.Qg)(e)?e.then((e=>(n(),e)),(e=>{throw t(e),n(),e})):(n(),e)}(i,t,n)}((()=>t(l)),(()=>{if(l){const{status:e}=(0,o.et)(l);e&&"ok"!==e||l.setStatus("internal_error")}}),(()=>l&&l.end()))}))))}function d(e){if(!(0,l.w)())return;const t=b(e),n=(0,s.BF)(),i=e.scope?e.scope.getSpan():(0,a.o5)().getSpan();if(e.onlyIfParent&&!i)return;const o=(e.scope||(0,a.o5)()).clone();return u(n,{parentSpan:i,spanContext:t,forceTransaction:e.forceTransaction,scope:o})}function u(e,{parentSpan:t,spanContext:n,forceTransaction:a,scope:c}){if(!(0,l.w)())return;const g=(0,s.rm)();let d;if(t&&!a)d=t.startChild(n);else if(t){const i=(0,r.k)(t),{traceId:s,spanId:a}=t.spanContext(),c=(0,o.pK)(t);d=e.startTransaction({traceId:s,parentSpanId:a,parentSampled:c,...n,metadata:{dynamicSamplingContext:i,...n.metadata}})}else{const{traceId:t,dsc:i,parentSpanId:s,sampled:o}={...g.getPropagationContext(),...c.getPropagationContext()};d=e.startTransaction({traceId:t,parentSpanId:s,parentSampled:o,...n,metadata:{dynamicSamplingContext:i,...n.metadata}})}return c.setSpan(d),function(e,t,n){e&&((0,i.my)(e,p,n),(0,i.my)(e,I,t))}(d,c,g),d}function b(e){if(e.startTime){const t={...e};return t.startTimestamp=(0,o.cI)(e.startTime),delete t.startTime,t}return e}const I="_sentryScope",p="_sentryIsolationScope";function C(e){return{scope:e[I],isolationScope:e[p]}}},9049:(e,t,n)=>{"use strict";n.d(t,{Z:()=>b});var i=n(1041),s=n(6202),o=n(7022),r=n(6588),a=n(741),c=n(5071),l=n(5895),g=n(9738),d=n(7037),u=n(9589);class b extends d.L{constructor(e,t){super(e),this._contexts={},this._hub=t||(0,r.BF)(),this._name=e.name||"",this._metadata={...e.metadata},this._trimEnd=e.trimEnd,this.transaction=this;const n=this._metadata.dynamicSamplingContext;n&&(this._frozenDynamicSamplingContext={...n})}get name(){return this._name}set name(e){this.setName(e)}get metadata(){return{source:"custom",spanMetadata:{},...this._metadata,...this._attributes[c.i_]&&{source:this._attributes[c.i_]},...this._attributes[c.sy]&&{sampleRate:this._attributes[c.sy]}}}set metadata(e){this._metadata=e}setName(e,t="custom"){this._name=e,this.setAttribute(c.i_,t)}updateName(e){return this._name=e,this}initSpanRecorder(e=1e3){this.spanRecorder||(this.spanRecorder=new d.l(e)),this.spanRecorder.add(this)}setContext(e,t){null===t?delete this._contexts[e]:this._contexts[e]=t}setMeasurement(e,t,n=""){this._measurements[e]={value:t,unit:n}}setMetadata(e){this._metadata={...this._metadata,...e}}end(e){const t=(0,l.cI)(e),n=this._finishTransaction(t);if(n)return this._hub.captureEvent(n)}toContext(){const e=super.toContext();return(0,i.Ce)({...e,name:this._name,trimEnd:this._trimEnd})}updateWithContext(e){return super.updateWithContext(e),this._name=e.name||"",this._trimEnd=e.trimEnd,this}getDynamicSamplingContext(){return(0,g.k)(this)}setHub(e){this._hub=e}getProfileId(){if(void 0!==this._contexts&&void 0!==this._contexts.profile)return this._contexts.profile.profile_id}_finishTransaction(e){if(void 0!==this._endTime)return;this._name||(o.T&&s.vF.warn("Transaction has no name, falling back to ``."),this._name=""),super.end(e);const t=this._hub.getClient();if(t&&t.emit&&t.emit("finishTransaction",this),!0!==this._sampled)return o.T&&s.vF.log("[Tracing] Discarding transaction because its trace was not chosen to be sampled."),void(t&&t.recordDroppedEvent("sample_rate","transaction"));const n=this.spanRecorder?this.spanRecorder.spans.filter((e=>e!==this&&(0,l.et)(e).timestamp)):[];if(this._trimEnd&&n.length>0){const e=n.map((e=>(0,l.et)(e).timestamp)).filter(Boolean);this._endTime=e.reduce(((e,t)=>e>t?e:t))}const{scope:r,isolationScope:c}=(0,u.Lb)(this),{metadata:d}=this,{source:b}=d,I={contexts:{...this._contexts,trace:(0,l.kX)(this)},spans:n,start_timestamp:this._startTime,tags:this.tags,timestamp:this._endTime,transaction:this._name,type:"transaction",sdkProcessingMetadata:{...d,capturedSpanScope:r,capturedSpanIsolationScope:c,...(0,i.Ce)({dynamicSamplingContext:(0,g.k)(this)})},_metrics_summary:(0,a.g)(this),...b&&{transaction_info:{source:b}}};return Object.keys(this._measurements).length>0&&(o.T&&s.vF.log("[Measurements] Adding measurements to transaction",JSON.stringify(this._measurements,void 0,2)),I.measurements=this._measurements),o.T&&s.vF.log(`[Tracing] Finishing ${this.op} transaction: ${this._name}.`),I}}},1692:(e,t,n)=>{"use strict";n.d(t,{Z7:()=>o,nc:()=>r});var i=n(1206),s=n(6588);function o(e){return(e||(0,s.BF)()).getScope().getTransaction()}const r=i.nc},9266:(e,t,n)=>{"use strict";function i(e){return e.transaction}n.d(t,{z:()=>i})},5177:(e,t,n)=>{"use strict";n.d(t,{w:()=>s});var i=n(9071);function s(e){if("boolean"==typeof __SENTRY_TRACING__&&!__SENTRY_TRACING__)return!1;const t=(0,i.KU)(),n=e||t&&t.getOptions();return!!n&&(n.enableTracing||"tracesSampleRate"in n||"tracesSampler"in n)}},5895:(e,t,n)=>{"use strict";n.d(t,{CC:()=>r,Qh:()=>l,aO:()=>a,cI:()=>g,et:()=>u,kX:()=>c,pK:()=>b});var i=n(1041),s=n(1206),o=n(7567);const r=0,a=1;function c(e){const{spanId:t,traceId:n}=e.spanContext(),{data:s,op:o,parent_span_id:r,status:a,tags:c,origin:l}=u(e);return(0,i.Ce)({data:s,op:o,parent_span_id:r,span_id:t,status:a,tags:c,trace_id:n,origin:l})}function l(e){const{traceId:t,spanId:n}=e.spanContext(),i=b(e);return(0,s.TC)(t,n,i)}function g(e){return"number"==typeof e?d(e):Array.isArray(e)?e[0]+e[1]/1e9:e instanceof Date?d(e.getTime()):(0,o.zf)()}function d(e){return e>9999999999?e/1e3:e}function u(e){return function(e){return"function"==typeof e.getSpanJSON}(e)?e.getSpanJSON():"function"==typeof e.toJSON?e.toJSON():{}}function b(e){const{traceFlags:t}=e.spanContext();return Boolean(t&a)}},8562:(e,t,n)=>{"use strict";n.d(t,{De:()=>d,hF:()=>r,yD:()=>g});var i=n(9610),s=n(138),o=n(6202);const r="baggage",a="sentry-",c=/^sentry-/,l=8192;function g(e){if(!(0,s.Kg)(e)&&!Array.isArray(e))return;let t={};if(Array.isArray(e))t=e.reduce(((e,t)=>{const n=u(t);for(const t of Object.keys(n))e[t]=n[t];return e}),{});else{if(!e)return;t=u(e)}const n=Object.entries(t).reduce(((e,[t,n])=>(t.match(c)&&(e[t.slice(a.length)]=n),e)),{});return Object.keys(n).length>0?n:void 0}function d(e){if(e)return function(e){if(0!==Object.keys(e).length)return Object.entries(e).reduce(((e,[t,n],s)=>{const r=`${encodeURIComponent(t)}=${encodeURIComponent(n)}`,a=0===s?r:`${e},${r}`;return a.length>l?(i.T&&o.vF.warn(`Not adding key: ${t} with val: ${n} to baggage header due to exceeding baggage size limits.`),e):a}),"")}(Object.entries(e).reduce(((e,[t,n])=>(n&&(e[`${a}${t}`]=n),e)),{}))}function u(e){return e.split(",").map((e=>e.split("=").map((e=>decodeURIComponent(e.trim()))))).reduce(((e,[t,n])=>(e[t]=n,e)),{})}},9610:(e,t,n)=>{"use strict";n.d(t,{T:()=>i});const i="undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__},6768:(e,t,n)=>{"use strict";n.d(t,{AS:()=>l,aj:()=>g,s5:()=>c});var i=n(9610),s=n(6202),o=n(8231);const r={},a={};function c(e,t){r[e]=r[e]||[],r[e].push(t)}function l(e,t){a[e]||(t(),a[e]=!0)}function g(e,t){const n=e&&r[e];if(n)for(const r of n)try{r(t)}catch(t){i.T&&s.vF.error(`Error while triggering instrumentation handler.\nType: ${e}\nName: ${(0,o.qQ)(r)}\nError:`,t)}}},138:(e,t,n)=>{"use strict";n.d(t,{Kg:()=>o,Qd:()=>r,Qg:()=>c,gd:()=>a,tH:()=>g,yr:()=>l});const i=Object.prototype.toString;function s(e,t){return i.call(e)===`[object ${t}]`}function o(e){return s(e,"String")}function r(e){return s(e,"Object")}function a(e){return s(e,"RegExp")}function c(e){return Boolean(e&&e.then&&"function"==typeof e.then)}function l(e){return"number"==typeof e&&e!=e}function g(e,t){try{return e instanceof t}catch(e){return!1}}},6202:(e,t,n)=>{"use strict";n.d(t,{pq:()=>a,vF:()=>c});var i=n(9610),s=n(2231);const o=["debug","info","warn","error","log","assert","trace"],r={};function a(e){if(!("console"in s.OW))return e();const t=s.OW.console,n={},i=Object.keys(r);i.forEach((e=>{const i=r[e];n[e]=t[e],t[e]=i}));try{return e()}finally{i.forEach((e=>{t[e]=n[e]}))}}const c=function(){let e=!1;const t={enable:()=>{e=!0},disable:()=>{e=!1},isEnabled:()=>e};return i.T?o.forEach((n=>{t[n]=(...t)=>{e&&a((()=>{s.OW.console[n](`Sentry Logger [${n}]:`,...t)}))}})):o.forEach((e=>{t[e]=()=>{}})),t}()},4902:(e,t,n)=>{"use strict";n.d(t,{eJ:()=>s,k9:()=>o});var i=n(2231);function s(){const e=i.OW,t=e.crypto||e.msCrypto;let n=()=>16*Math.random();try{if(t&&t.randomUUID)return t.randomUUID().replace(/-/g,"");t&&t.getRandomValues&&(n=()=>{const e=new Uint8Array(1);return t.getRandomValues(e),e[0]})}catch(e){}return([1e7]+1e3+4e3+8e3+1e11).replace(/[018]/g,(e=>(e^(15&n())>>e/4).toString(16)))}function o(e){return Array.isArray(e)?e:[e]}},8560:(e,t,n)=>{"use strict";function i(){return!("undefined"!=typeof __SENTRY_BROWSER_BUNDLE__&&__SENTRY_BROWSER_BUNDLE__)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0)}function s(e,t){return e.require(t)}function o(t){let n;try{n=s(e,t)}catch(e){}try{const{cwd:i}=s(e,"process");n=s(e,`${i()}/node_modules/${t}`)}catch(e){}return n}n.d(t,{fj:()=>s,wD:()=>i,Vw:()=>o}),e=n.hmd(e)},1041:(e,t,n)=>{"use strict";n.d(t,{Ce:()=>c,GS:()=>r,my:()=>a});var i=n(9610),s=n(138),o=n(6202);function r(e,t,n){if(!(t in e))return;const i=e[t],s=n(i);"function"==typeof s&&function(e,t){try{const n=t.prototype||{};e.prototype=t.prototype=n,a(e,"__sentry_original__",t)}catch(e){}}(s,i),e[t]=s}function a(e,t,n){try{Object.defineProperty(e,t,{value:n,writable:!0,configurable:!0})}catch(n){i.T&&o.vF.log(`Failed to add non-enumerable property "${t}" to object`,e)}}function c(e){return l(e,new Map)}function l(e,t){if(function(e){if(!(0,s.Qd)(e))return!1;try{const t=Object.getPrototypeOf(e).constructor.name;return!t||"Object"===t}catch(e){return!0}}(e)){const n=t.get(e);if(void 0!==n)return n;const i={};t.set(e,i);for(const n of Object.keys(e))void 0!==e[n]&&(i[n]=l(e[n],t));return i}if(Array.isArray(e)){const n=t.get(e);if(void 0!==n)return n;const i=[];return t.set(e,i),e.forEach((e=>{i.push(l(e,t))})),i}return e}},8231:(e,t,n)=>{"use strict";n.d(t,{qQ:()=>s});const i="";function s(e){try{return e&&"function"==typeof e&&e.name||i}catch(e){return i}}},7567:(e,t,n)=>{"use strict";n.d(t,{k3:()=>c,lu:()=>o,zf:()=>r});var i=n(2231);const s=1e3;function o(){return Date.now()/s}const r=function(){const{performance:e}=i.OW;if(!e||!e.now)return o;const t=Date.now()-e.now(),n=null==e.timeOrigin?t:e.timeOrigin;return()=>(n+e.now())/s}();let a;const c=(()=>{const{performance:e}=i.OW;if(!e||!e.now)return void(a="none");const t=36e5,n=e.now(),s=Date.now(),o=e.timeOrigin?Math.abs(e.timeOrigin+n-s):t,r=o{"use strict";n.d(t,{MI:()=>o,TC:()=>c,kM:()=>a,nc:()=>r});var i=n(8562),s=n(4902);const o=new RegExp("^[ \\t]*([0-9a-f]{32})?-?([0-9a-f]{16})?-?([01])?[ \\t]*$");function r(e){if(!e)return;const t=e.match(o);if(!t)return;let n;return"1"===t[3]?n=!0:"0"===t[3]&&(n=!1),{traceId:t[1],parentSampled:n,parentSpanId:t[2]}}function a(e,t){const n=r(e),o=(0,i.yD)(t),{traceId:a,parentSpanId:c,parentSampled:l}=n||{};return n?{traceId:a||(0,s.eJ)(),parentSpanId:c||(0,s.eJ)().substring(16),spanId:(0,s.eJ)().substring(16),sampled:l,dsc:o||{}}:{traceId:a||(0,s.eJ)(),spanId:(0,s.eJ)().substring(16)}}function c(e=(0,s.eJ)(),t=(0,s.eJ)().substring(16),n){let i="";return void 0!==n&&(i=n?"-1":"-0"),`${e}-${t}${i}`}},2231:(e,t,n)=>{"use strict";function i(e){return e&&e.Math==Math?e:void 0}n.d(t,{BY:()=>r,OW:()=>s,VZ:()=>o});const s="object"==typeof globalThis&&i(globalThis)||"object"==typeof window&&i(window)||"object"==typeof self&&i(self)||"object"==typeof global&&i(global)||function(){return this}()||{};function o(){return s}function r(e,t,n){const i=n||s,o=i.__SENTRY__=i.__SENTRY__||{};return o[e]||(o[e]=t())}},2967:(e,t,n)=>{"use strict";n.d(t,{U:()=>i});const i="production"},2220:(e,t,n)=>{"use strict";n.d(t,{T:()=>i});const i="undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__},2531:(e,t,n)=>{"use strict";n.d(t,{jB:()=>g,lG:()=>c,lb:()=>l});var i=n(6341),s=n(690),o=n(7412),r=n(3816),a=n(2220);function c(){return(0,i.BY)("globalEventProcessors",(()=>[]))}function l(e){c().push(e)}function g(e,t,n,i=0){return new s.T2(((s,c)=>{const l=e[i];if(null===t||"function"!=typeof l)s(t);else{const d=l({...t},n);a.T&&l.id&&null===d&&o.vF.log(`Event processor "${l.id}" dropped event`),(0,r.Qg)(d)?d.then((t=>g(e,t,n,i+1).then(s))).then(null,c):g(e,d,n,i+1).then(s).then(null,c)}}))}},3741:(e,t,n)=>{"use strict";n.d(t,{Cp:()=>b,Dp:()=>w,J0:()=>F,J5:()=>J,KU:()=>N,NA:()=>B,PN:()=>C,Q:()=>S,SE:()=>R,T$:()=>Y,VN:()=>H,Wt:()=>G,ZQ:()=>h,bX:()=>X,cx:()=>y,gV:()=>A,hb:()=>V,ky:()=>k,l7:()=>Z,nb:()=>v,o:()=>m,o5:()=>K,r:()=>p,rB:()=>f,v4:()=>W,wd:()=>I});var i=n(7412),s=n(6936),o=n(9297),r=n(3816),a=n(6341),c=n(2967),l=n(2220),g=n(6641),d=n(7058),u=n(9475);function b(e,t){return(0,g.BF)().captureException(e,(0,u.li)(t))}function I(e,t){const n="string"==typeof t?t:void 0,i="string"!=typeof t?{captureContext:t}:void 0;return(0,g.BF)().captureMessage(e,n,i)}function p(e,t){return(0,g.BF)().captureEvent(e,t)}function C(e){(0,g.BF)().configureScope(e)}function h(e,t){(0,g.BF)().addBreadcrumb(e,t)}function m(e,t){(0,g.BF)().setContext(e,t)}function y(e){(0,g.BF)().setExtras(e)}function Z(e,t){(0,g.BF)().setExtra(e,t)}function G(e){(0,g.BF)().setTags(e)}function B(e,t){(0,g.BF)().setTag(e,t)}function A(e){(0,g.BF)().setUser(e)}function W(...e){const t=(0,g.BF)();if(2===e.length){const[n,i]=e;return n?t.withScope((()=>(t.getStackTop().scope=n,i(n)))):t.withScope(i)}return t.withScope(e[0])}function f(e){return(0,g.fx)((()=>e((0,g.rm)())))}function V(e,t){return W((n=>(n.setSpan(e),t(n))))}function v(e,t){return(0,g.BF)().startTransaction({...e},t)}function R(e,t){const n=K(),o=N();if(o){if(o.captureCheckIn)return o.captureCheckIn(e,t,n);l.T&&i.vF.warn("Cannot capture check-in. Client does not support sending check-ins.")}else l.T&&i.vF.warn("Cannot capture check-in. No client defined.");return(0,s.eJ)()}function Y(e,t,n){const i=R({monitorSlug:e,status:"in_progress"},n),s=(0,o.zf)();function a(t){R({monitorSlug:e,status:t,checkInId:i,duration:(0,o.zf)()-s})}let c;try{c=t()}catch(e){throw a("error"),e}return(0,r.Qg)(c)?Promise.resolve(c).then((()=>{a("ok")}),(()=>{a("error")})):a("ok"),c}async function X(e){const t=N();return t?t.flush(e):(l.T&&i.vF.warn("Cannot flush events. No client defined."),Promise.resolve(!1))}async function H(e){const t=N();return t?t.close(e):(l.T&&i.vF.warn("Cannot flush events and disable SDK. No client defined."),Promise.resolve(!1))}function S(){return(0,g.BF)().lastEventId()}function N(){return(0,g.BF)().getClient()}function w(){return!!N()}function K(){return(0,g.BF)().getScope()}function F(e){const t=N(),n=(0,g.rm)(),i=K(),{release:s,environment:o=c.U}=t&&t.getOptions()||{},{userAgent:r}=a.OW.navigator||{},l=(0,d.fj)({release:s,environment:o,user:i.getUser()||n.getUser(),...r&&{userAgent:r},...e}),u=n.getSession();return u&&"ok"===u.status&&(0,d.qO)(u,{status:"exited"}),k(),n.setSession(l),i.setSession(l),l}function k(){const e=(0,g.rm)(),t=K(),n=t.getSession()||e.getSession();n&&(0,d.Vu)(n),_(),e.setSession(),t.setSession()}function _(){const e=(0,g.rm)(),t=K(),n=N(),i=t.getSession()||e.getSession();i&&n&&n.captureSession&&n.captureSession(i)}function J(e=!1){e?k():_()}},6641:(e,t,n)=>{"use strict";n.d(t,{BF:()=>m,EU:()=>C,Me:()=>f,TF:()=>G,YZ:()=>p,fx:()=>A,gM:()=>h,lq:()=>V,nX:()=>B,rm:()=>y});var i=n(3816),s=n(6936),o=n(9297),r=n(7412),a=n(6341),c=n(2967),l=n(2220),g=n(2486),d=n(7058),u=n(7986);const b=parseFloat(u.M),I=100;class p{constructor(e,t,n,i=b){let s,o;this._version=i,t?s=t:(s=new g.HG,s.setClient(e)),n?o=n:(o=new g.HG,o.setClient(e)),this._stack=[{scope:s}],e&&this.bindClient(e),this._isolationScope=o}isOlderThan(e){return this._version(this.popScope(),e)),(e=>{throw this.popScope(),e})):(this.popScope(),n)}getClient(){return this.getStackTop().client}getScope(){return this.getStackTop().scope}getIsolationScope(){return this._isolationScope}getStack(){return this._stack}getStackTop(){return this._stack[this._stack.length-1]}captureException(e,t){const n=this._lastEventId=t&&t.event_id?t.event_id:(0,s.eJ)(),i=new Error("Sentry syntheticException");return this.getScope().captureException(e,{originalException:e,syntheticException:i,...t,event_id:n}),n}captureMessage(e,t,n){const i=this._lastEventId=n&&n.event_id?n.event_id:(0,s.eJ)(),o=new Error(e);return this.getScope().captureMessage(e,t,{originalException:e,syntheticException:o,...n,event_id:i}),i}captureEvent(e,t){const n=t&&t.event_id?t.event_id:(0,s.eJ)();return e.type||(this._lastEventId=n),this.getScope().captureEvent(e,{...t,event_id:n}),n}lastEventId(){return this._lastEventId}addBreadcrumb(e,t){const{scope:n,client:i}=this.getStackTop();if(!i)return;const{beforeBreadcrumb:s=null,maxBreadcrumbs:a=I}=i.getOptions&&i.getOptions()||{};if(a<=0)return;const c={timestamp:(0,o.lu)(),...e},l=s?(0,r.pq)((()=>s(c,t))):c;null!==l&&(i.emit&&i.emit("beforeAddBreadcrumb",l,t),n.addBreadcrumb(l,a))}setUser(e){this.getScope().setUser(e),this.getIsolationScope().setUser(e)}setTags(e){this.getScope().setTags(e),this.getIsolationScope().setTags(e)}setExtras(e){this.getScope().setExtras(e),this.getIsolationScope().setExtras(e)}setTag(e,t){this.getScope().setTag(e,t),this.getIsolationScope().setTag(e,t)}setExtra(e,t){this.getScope().setExtra(e,t),this.getIsolationScope().setExtra(e,t)}setContext(e,t){this.getScope().setContext(e,t),this.getIsolationScope().setContext(e,t)}configureScope(e){const{scope:t,client:n}=this.getStackTop();n&&e(t)}run(e){const t=h(this);try{e(this)}finally{h(t)}}getIntegration(e){const t=this.getClient();if(!t)return null;try{return t.getIntegration(e)}catch(t){return l.T&&r.vF.warn(`Cannot retrieve integration ${e.id} from the current Hub`),null}}startTransaction(e,t){const n=this._callExtensionMethod("startTransaction",e,t);return l.T&&!n&&(this.getClient()?r.vF.warn("Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init':\nSentry.addTracingExtensions();\nSentry.init({...});\n"):r.vF.warn("Tracing extension 'startTransaction' is missing. You should 'init' the SDK before calling 'startTransaction'")),n}traceHeaders(){return this._callExtensionMethod("traceHeaders")}captureSession(e=!1){if(e)return this.endSession();this._sendSessionUpdate()}endSession(){const e=this.getStackTop().scope,t=e.getSession();t&&(0,d.Vu)(t),this._sendSessionUpdate(),e.setSession()}startSession(e){const{scope:t,client:n}=this.getStackTop(),{release:i,environment:s=c.U}=n&&n.getOptions()||{},{userAgent:o}=a.OW.navigator||{},r=(0,d.fj)({release:i,environment:s,user:t.getUser(),...o&&{userAgent:o},...e}),l=t.getSession&&t.getSession();return l&&"ok"===l.status&&(0,d.qO)(l,{status:"exited"}),this.endSession(),t.setSession(r),r}shouldSendDefaultPii(){const e=this.getClient(),t=e&&e.getOptions();return Boolean(t&&t.sendDefaultPii)}_sendSessionUpdate(){const{scope:e,client:t}=this.getStackTop(),n=e.getSession();n&&t&&t.captureSession&&t.captureSession(n)}_callExtensionMethod(e,...t){const n=C().__SENTRY__;if(n&&n.extensions&&"function"==typeof n.extensions[e])return n.extensions[e].apply(this,t);l.T&&r.vF.warn(`Extension method ${e} couldn't be found, doing nothing.`)}}function C(){return a.OW.__SENTRY__=a.OW.__SENTRY__||{extensions:{},hub:void 0},a.OW}function h(e){const t=C(),n=f(t);return V(t,e),n}function m(){const e=C();if(e.__SENTRY__&&e.__SENTRY__.acs){const t=e.__SENTRY__.acs.getCurrentHub();if(t)return t}return Z(e)}function y(){return m().getIsolationScope()}function Z(e=C()){return W(e)&&!f(e).isOlderThan(b)||V(e,new p),f(e)}function G(e,t=Z()){if(!W(e)||f(e).isOlderThan(b)){const n=t.getClient(),i=t.getScope(),s=t.getIsolationScope();V(e,new p(n,i.clone(),s.clone()))}}function B(e){const t=C();t.__SENTRY__=t.__SENTRY__||{},t.__SENTRY__.acs=e}function A(e,t={}){const n=C();return n.__SENTRY__&&n.__SENTRY__.acs?n.__SENTRY__.acs.runWithAsyncContext(e,t):e()}function W(e){return!!(e&&e.__SENTRY__&&e.__SENTRY__.hub)}function f(e){return(0,a.BY)("hub",(()=>new p),e)}function V(e,t){return!!e&&((e.__SENTRY__=e.__SENTRY__||{}).hub=t,!0)}},5836:(e,t,n)=>{"use strict";n.d(t,{F:()=>p,P$:()=>d,Q8:()=>I,_C:()=>C,lc:()=>u,mH:()=>g,qm:()=>b});var i=n(6936),s=n(7412),o=n(2220),r=n(2531),a=n(3741),c=n(6641);const l=[];function g(e){const t=e.defaultIntegrations||[],n=e.integrations;let s;t.forEach((e=>{e.isDefaultInstance=!0})),s=Array.isArray(n)?[...t,...n]:"function"==typeof n?(0,i.k9)(n(t)):t;const o=function(e){const t={};return e.forEach((e=>{const{name:n}=e,i=t[n];i&&!i.isDefaultInstance&&e.isDefaultInstance||(t[n]=e)})),Object.keys(t).map((e=>t[e]))}(s),r=function(e,t){for(let t=0;t{t&&b(e,t,n)})),n}function u(e,t){for(const n of t)n&&n.afterAllSetup&&n.afterAllSetup(e)}function b(e,t,n){if(n[t.name])o.T&&s.vF.log(`Integration skipped because it was already installed: ${t.name}`);else{if(n[t.name]=t,-1===l.indexOf(t.name)&&(t.setupOnce(r.lb,c.BF),l.push(t.name)),t.setup&&"function"==typeof t.setup&&t.setup(e),e.on&&"function"==typeof t.preprocessEvent){const n=t.preprocessEvent.bind(t);e.on("preprocessEvent",((t,i)=>n(t,i,e)))}if(e.addEventProcessor&&"function"==typeof t.processEvent){const n=t.processEvent.bind(t),i=Object.assign(((t,i)=>n(t,i,e)),{id:t.name});e.addEventProcessor(i)}o.T&&s.vF.log(`Integration installed: ${t.name}`)}}function I(e){const t=(0,a.KU)();t&&t.addIntegration?t.addIntegration(e):o.T&&s.vF.warn(`Cannot add integration "${e.name}" because no SDK Client is available.`)}function p(e,t){return Object.assign((function(...e){return t(...e)}),{id:e})}function C(e){return e}},2486:(e,t,n)=>{"use strict";n.d(t,{HG:()=>d,m6:()=>u});var i=n(3816),s=n(9297),o=n(6936),r=n(7412),a=n(2531),c=n(7058),l=n(1535);let g;class d{constructor(){this._notifyingListeners=!1,this._scopeListeners=[],this._eventProcessors=[],this._breadcrumbs=[],this._attachments=[],this._user={},this._tags={},this._extra={},this._contexts={},this._sdkProcessingMetadata={},this._propagationContext=b()}static clone(e){return e?e.clone():new d}clone(){const e=new d;return e._breadcrumbs=[...this._breadcrumbs],e._tags={...this._tags},e._extra={...this._extra},e._contexts={...this._contexts},e._user=this._user,e._level=this._level,e._span=this._span,e._session=this._session,e._transactionName=this._transactionName,e._fingerprint=this._fingerprint,e._eventProcessors=[...this._eventProcessors],e._requestSession=this._requestSession,e._attachments=[...this._attachments],e._sdkProcessingMetadata={...this._sdkProcessingMetadata},e._propagationContext={...this._propagationContext},e._client=this._client,e}setClient(e){this._client=e}getClient(){return this._client}addScopeListener(e){this._scopeListeners.push(e)}addEventProcessor(e){return this._eventProcessors.push(e),this}setUser(e){return this._user=e||{email:void 0,id:void 0,ip_address:void 0,segment:void 0,username:void 0},this._session&&(0,c.qO)(this._session,{user:e}),this._notifyScopeListeners(),this}getUser(){return this._user}getRequestSession(){return this._requestSession}setRequestSession(e){return this._requestSession=e,this}setTags(e){return this._tags={...this._tags,...e},this._notifyScopeListeners(),this}setTag(e,t){return this._tags={...this._tags,[e]:t},this._notifyScopeListeners(),this}setExtras(e){return this._extra={...this._extra,...e},this._notifyScopeListeners(),this}setExtra(e,t){return this._extra={...this._extra,[e]:t},this._notifyScopeListeners(),this}setFingerprint(e){return this._fingerprint=e,this._notifyScopeListeners(),this}setLevel(e){return this._level=e,this._notifyScopeListeners(),this}setTransactionName(e){return this._transactionName=e,this._notifyScopeListeners(),this}setContext(e,t){return null===t?delete this._contexts[e]:this._contexts[e]=t,this._notifyScopeListeners(),this}setSpan(e){return this._span=e,this._notifyScopeListeners(),this}getSpan(){return this._span}getTransaction(){const e=this._span;return e&&e.transaction}setSession(e){return e?this._session=e:delete this._session,this._notifyScopeListeners(),this}getSession(){return this._session}update(e){if(!e)return this;const t="function"==typeof e?e(this):e;if(t instanceof d){const e=t.getScopeData();this._tags={...this._tags,...e.tags},this._extra={...this._extra,...e.extra},this._contexts={...this._contexts,...e.contexts},e.user&&Object.keys(e.user).length&&(this._user=e.user),e.level&&(this._level=e.level),e.fingerprint.length&&(this._fingerprint=e.fingerprint),t.getRequestSession()&&(this._requestSession=t.getRequestSession()),e.propagationContext&&(this._propagationContext=e.propagationContext)}else if((0,i.Qd)(t)){const t=e;this._tags={...this._tags,...t.tags},this._extra={...this._extra,...t.extra},this._contexts={...this._contexts,...t.contexts},t.user&&(this._user=t.user),t.level&&(this._level=t.level),t.fingerprint&&(this._fingerprint=t.fingerprint),t.requestSession&&(this._requestSession=t.requestSession),t.propagationContext&&(this._propagationContext=t.propagationContext)}return this}clear(){return this._breadcrumbs=[],this._tags={},this._extra={},this._user={},this._contexts={},this._level=void 0,this._transactionName=void 0,this._fingerprint=void 0,this._requestSession=void 0,this._span=void 0,this._session=void 0,this._notifyScopeListeners(),this._attachments=[],this._propagationContext=b(),this}addBreadcrumb(e,t){const n="number"==typeof t?t:100;if(n<=0)return this;const i={timestamp:(0,s.lu)(),...e},o=this._breadcrumbs;return o.push(i),this._breadcrumbs=o.length>n?o.slice(-n):o,this._notifyScopeListeners(),this}getLastBreadcrumb(){return this._breadcrumbs[this._breadcrumbs.length-1]}clearBreadcrumbs(){return this._breadcrumbs=[],this._notifyScopeListeners(),this}addAttachment(e){return this._attachments.push(e),this}getAttachments(){return this.getScopeData().attachments}clearAttachments(){return this._attachments=[],this}getScopeData(){const{_breadcrumbs:e,_attachments:t,_contexts:n,_tags:i,_extra:s,_user:o,_level:r,_fingerprint:a,_eventProcessors:c,_propagationContext:l,_sdkProcessingMetadata:g,_transactionName:d,_span:u}=this;return{breadcrumbs:e,attachments:t,contexts:n,tags:i,extra:s,user:o,level:r,fingerprint:a||[],eventProcessors:c,propagationContext:l,sdkProcessingMetadata:g,transactionName:d,span:u}}applyToEvent(e,t={},n=[]){(0,l.e2)(e,this.getScopeData());const i=[...n,...(0,a.lG)(),...this._eventProcessors];return(0,a.jB)(i,e,t)}setSDKProcessingMetadata(e){return this._sdkProcessingMetadata={...this._sdkProcessingMetadata,...e},this}setPropagationContext(e){return this._propagationContext=e,this}getPropagationContext(){return this._propagationContext}captureException(e,t){const n=t&&t.event_id?t.event_id:(0,o.eJ)();if(!this._client)return r.vF.warn("No client configured on scope - will not capture exception!"),n;const i=new Error("Sentry syntheticException");return this._client.captureException(e,{originalException:e,syntheticException:i,...t,event_id:n},this),n}captureMessage(e,t,n){const i=n&&n.event_id?n.event_id:(0,o.eJ)();if(!this._client)return r.vF.warn("No client configured on scope - will not capture message!"),i;const s=new Error(e);return this._client.captureMessage(e,t,{originalException:e,syntheticException:s,...n,event_id:i},this),i}captureEvent(e,t){const n=t&&t.event_id?t.event_id:(0,o.eJ)();return this._client?(this._client.captureEvent(e,{...t,event_id:n},this),n):(r.vF.warn("No client configured on scope - will not capture event!"),n)}_notifyScopeListeners(){this._notifyingListeners||(this._notifyingListeners=!0,this._scopeListeners.forEach((e=>{e(this)})),this._notifyingListeners=!1)}}function u(){return g||(g=new d),g}function b(){return{traceId:(0,o.eJ)(),spanId:(0,o.eJ)().substring(16)}}},7058:(e,t,n)=>{"use strict";n.d(t,{Vu:()=>c,fj:()=>r,qO:()=>a});var i=n(9297),s=n(6936),o=n(4022);function r(e){const t=(0,i.zf)(),n={sid:(0,s.eJ)(),init:!0,timestamp:t,started:t,duration:0,status:"ok",errors:0,ignoreDuration:!1,toJSON:()=>function(e){return(0,o.Ce)({sid:`${e.sid}`,init:e.init,started:new Date(1e3*e.started).toISOString(),timestamp:new Date(1e3*e.timestamp).toISOString(),status:e.status,errors:e.errors,did:"number"==typeof e.did||"string"==typeof e.did?`${e.did}`:void 0,duration:e.duration,abnormal_mechanism:e.abnormal_mechanism,attrs:{release:e.release,environment:e.environment,ip_address:e.ipAddress,user_agent:e.userAgent}})}(n)};return e&&a(n,e),n}function a(e,t={}){if(t.user&&(!e.ipAddress&&t.user.ip_address&&(e.ipAddress=t.user.ip_address),e.did||t.did||(e.did=t.user.id||t.user.email||t.user.username)),e.timestamp=t.timestamp||(0,i.zf)(),t.abnormal_mechanism&&(e.abnormal_mechanism=t.abnormal_mechanism),t.ignoreDuration&&(e.ignoreDuration=t.ignoreDuration),t.sid&&(e.sid=32===t.sid.length?t.sid:(0,s.eJ)()),void 0!==t.init&&(e.init=t.init),!e.did&&t.did&&(e.did=`${t.did}`),"number"==typeof t.started&&(e.started=t.started),e.ignoreDuration)e.duration=void 0;else if("number"==typeof t.duration)e.duration=t.duration;else{const t=e.timestamp-e.started;e.duration=t>=0?t:0}t.release&&(e.release=t.release),t.environment&&(e.environment=t.environment),!e.ipAddress&&t.ipAddress&&(e.ipAddress=t.ipAddress),!e.userAgent&&t.userAgent&&(e.userAgent=t.userAgent),"number"==typeof t.errors&&(e.errors=t.errors),t.status&&(e.status=t.status)}function c(e,t){let n={};t?n={status:t}:"ok"===e.status&&(n={status:"exited"}),a(e,n)}},5452:(e,t,n)=>{"use strict";n.d(t,{k:()=>l,l:()=>c});var i=n(4022),s=n(2967),o=n(3741),r=n(4636),a=n(3445);function c(e,t,n){const o=t.getOptions(),{publicKey:r}=t.getDsn()||{},{segment:a}=n&&n.getUser()||{},c=(0,i.Ce)({environment:o.environment||s.U,release:o.release,user_segment:a,public_key:r,trace_id:e});return t.emit&&t.emit("createDsc",c),c}function l(e){const t=(0,o.KU)();if(!t)return{};const n=c((0,a.et)(e).trace_id||"",t,(0,o.o5)()),i=(0,r.z)(e);if(!i)return n;const s=i&&i._frozenDynamicSamplingContext;if(s)return s;const{sampleRate:l,source:g}=i.metadata;null!=l&&(n.sample_rate=`${l}`);const d=(0,a.et)(i);return g&&"url"!==g&&(n.transaction=d.description),n.sampled=String((0,a.pK)(i)),t.emit&&t.emit("createDsc",n),n}},1535:(e,t,n)=>{"use strict";n.d(t,{Rg:()=>l,e2:()=>c});var i=n(4022),s=n(6936),o=n(5452),r=n(4636),a=n(3445);function c(e,t){const{fingerprint:n,span:c,breadcrumbs:l,sdkProcessingMetadata:g}=t;!function(e,t){const{extra:n,tags:s,user:o,contexts:r,level:a,transactionName:c}=t,l=(0,i.Ce)(n);l&&Object.keys(l).length&&(e.extra={...l,...e.extra});const g=(0,i.Ce)(s);g&&Object.keys(g).length&&(e.tags={...g,...e.tags});const d=(0,i.Ce)(o);d&&Object.keys(d).length&&(e.user={...d,...e.user});const u=(0,i.Ce)(r);u&&Object.keys(u).length&&(e.contexts={...u,...e.contexts}),a&&(e.level=a),c&&(e.transaction=c)}(e,t),c&&function(e,t){e.contexts={trace:(0,a.kX)(t),...e.contexts};const n=(0,r.z)(t);if(n){e.sdkProcessingMetadata={dynamicSamplingContext:(0,o.k)(t),...e.sdkProcessingMetadata};const i=(0,a.et)(n).description;i&&(e.tags={transaction:i,...e.tags})}}(e,c),function(e,t){e.fingerprint=e.fingerprint?(0,s.k9)(e.fingerprint):[],t&&(e.fingerprint=e.fingerprint.concat(t)),e.fingerprint&&!e.fingerprint.length&&delete e.fingerprint}(e,n),function(e,t){const n=[...e.breadcrumbs||[],...t];e.breadcrumbs=n.length?n:void 0}(e,l),function(e,t){e.sdkProcessingMetadata={...e.sdkProcessingMetadata,...t}}(e,g)}function l(e,t){const{extra:n,tags:i,user:s,contexts:o,level:r,sdkProcessingMetadata:a,breadcrumbs:c,fingerprint:l,eventProcessors:d,attachments:u,propagationContext:b,transactionName:I,span:p}=t;g(e,"extra",n),g(e,"tags",i),g(e,"user",s),g(e,"contexts",o),g(e,"sdkProcessingMetadata",a),r&&(e.level=r),I&&(e.transactionName=I),p&&(e.span=p),c.length&&(e.breadcrumbs=[...e.breadcrumbs,...c]),l.length&&(e.fingerprint=[...e.fingerprint,...l]),d.length&&(e.eventProcessors=[...e.eventProcessors,...d]),u.length&&(e.attachments=[...e.attachments,...u]),e.propagationContext={...e.propagationContext,...b}}function g(e,t,n){if(n&&Object.keys(n).length){e[t]={...e[t]};for(const i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[t][i]=n[i])}}},4636:(e,t,n)=>{"use strict";function i(e){return e.transaction}n.d(t,{z:()=>i})},9475:(e,t,n)=>{"use strict";n.d(t,{li:()=>p,mG:()=>b});var i=n(6936),s=n(9297),o=n(9653),r=n(6341),a=n(2181),c=n(2967),l=n(2531),g=n(2486),d=n(1535),u=n(3445);function b(e,t,n,b,p,C){const{normalizeDepth:h=3,normalizeMaxBreadth:m=1e3}=e,y={...t,event_id:t.event_id||n.event_id||(0,i.eJ)(),timestamp:t.timestamp||(0,s.lu)()},Z=n.integrations||e.integrations.map((e=>e.name));!function(e,t){const{environment:n,release:i,dist:s,maxValueLength:r=250}=t;"environment"in e||(e.environment="environment"in t?n:c.U),void 0===e.release&&void 0!==i&&(e.release=i),void 0===e.dist&&void 0!==s&&(e.dist=s),e.message&&(e.message=(0,o.xv)(e.message,r));const a=e.exception&&e.exception.values&&e.exception.values[0];a&&a.value&&(a.value=(0,o.xv)(a.value,r));const l=e.request;l&&l.url&&(l.url=(0,o.xv)(l.url,r))}(y,e),function(e,t){t.length>0&&(e.sdk=e.sdk||{},e.sdk.integrations=[...e.sdk.integrations||[],...t])}(y,Z),void 0===t.type&&function(e,t){const n=r.OW._sentryDebugIds;if(!n)return;let i;const s=I.get(t);s?i=s:(i=new Map,I.set(t,i));const o=Object.keys(n).reduce(((e,s)=>{let o;const r=i.get(s);r?o=r:(o=t(s),i.set(s,o));for(let t=o.length-1;t>=0;t--){const i=o[t];if(i.filename){e[i.filename]=n[s];break}}return e}),{});try{e.exception.values.forEach((e=>{e.stacktrace.frames.forEach((e=>{e.filename&&(e.debug_id=o[e.filename])}))}))}catch(e){}}(y,e.stackParser);const G=function(e,t){if(!t)return e;const n=e?e.clone():new g.HG;return n.update(t),n}(b,n.captureContext);n.mechanism&&(0,i.M6)(y,n.mechanism);const B=p&&p.getEventProcessors?p.getEventProcessors():[],A=(0,g.m6)().getScopeData();if(C){const e=C.getScopeData();(0,d.Rg)(A,e)}if(G){const e=G.getScopeData();(0,d.Rg)(A,e)}const W=[...n.attachments||[],...A.attachments];W.length&&(n.attachments=W),(0,d.e2)(y,A);const f=[...B,...(0,l.lG)(),...A.eventProcessors];return(0,l.jB)(f,y,n).then((e=>(e&&function(e){const t={};try{e.exception.values.forEach((e=>{e.stacktrace.frames.forEach((e=>{e.debug_id&&(e.abs_path?t[e.abs_path]=e.debug_id:e.filename&&(t[e.filename]=e.debug_id),delete e.debug_id)}))}))}catch(e){}if(0===Object.keys(t).length)return;e.debug_meta=e.debug_meta||{},e.debug_meta.images=e.debug_meta.images||[];const n=e.debug_meta.images;Object.keys(t).forEach((e=>{n.push({type:"sourcemap",code_file:e,debug_id:t[e]})}))}(e),"number"==typeof h&&h>0?function(e,t,n){if(!e)return null;const i={...e,...e.breadcrumbs&&{breadcrumbs:e.breadcrumbs.map((e=>({...e,...e.data&&{data:(0,a.S8)(e.data,t,n)}})))},...e.user&&{user:(0,a.S8)(e.user,t,n)},...e.contexts&&{contexts:(0,a.S8)(e.contexts,t,n)},...e.extra&&{extra:(0,a.S8)(e.extra,t,n)}};return e.contexts&&e.contexts.trace&&i.contexts&&(i.contexts.trace=e.contexts.trace,e.contexts.trace.data&&(i.contexts.trace.data=(0,a.S8)(e.contexts.trace.data,t,n))),e.spans&&(i.spans=e.spans.map((e=>{const i=(0,u.et)(e).data;return i&&(e.data=(0,a.S8)(i,t,n)),e}))),i}(e,h,m):e)))}const I=new WeakMap;function p(e){if(e)return function(e){return e instanceof g.HG||"function"==typeof e}(e)||function(e){return Object.keys(e).some((e=>C.includes(e)))}(e)?{captureContext:e}:e}const C=["user","level","extra","contexts","tags","fingerprint","requestSession","propagationContext"]},3445:(e,t,n)=>{"use strict";n.d(t,{CC:()=>r,Qh:()=>l,aO:()=>a,cI:()=>g,et:()=>u,kX:()=>c,pK:()=>b});var i=n(4022),s=n(6524),o=n(9297);const r=0,a=1;function c(e){const{spanId:t,traceId:n}=e.spanContext(),{data:s,op:o,parent_span_id:r,status:a,tags:c,origin:l}=u(e);return(0,i.Ce)({data:s,op:o,parent_span_id:r,span_id:t,status:a,tags:c,trace_id:n,origin:l})}function l(e){const{traceId:t,spanId:n}=e.spanContext(),i=b(e);return(0,s.TC)(t,n,i)}function g(e){return"number"==typeof e?d(e):Array.isArray(e)?e[0]+e[1]/1e9:e instanceof Date?d(e.getTime()):(0,o.zf)()}function d(e){return e>9999999999?e/1e3:e}function u(e){return function(e){return"function"==typeof e.getSpanJSON}(e)?e.getSpanJSON():"function"==typeof e.toJSON?e.toJSON():{}}function b(e){const{traceFlags:t}=e.spanContext();return Boolean(t&a)}},7986:(e,t,n)=>{"use strict";n.d(t,{M:()=>i});const i="7.118.0"},2710:(e,t,n)=>{"use strict";n.r(t),n.d(t,{DEFAULT_USER_INCLUDES:()=>lt,Handlers:()=>s,Http:()=>oi,Hub:()=>ne.YZ,Integrations:()=>uo,NodeClient:()=>Pt,SDK_VERSION:()=>Zt.M,SEMANTIC_ATTRIBUTE_SENTRY_OP:()=>J,SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN:()=>z,SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE:()=>_,SEMANTIC_ATTRIBUTE_SENTRY_SOURCE:()=>k,Scope:()=>Gt.HG,Undici:()=>Ni,addBreadcrumb:()=>c.ZQ,addEventProcessor:()=>Ce,addGlobalEventProcessor:()=>Bt.lb,addIntegration:()=>l.Q8,addRequestDataToEvent:()=>ut,anrIntegration:()=>ji.a,autoDiscoverNodePerformanceMonitoringIntegrations:()=>Wt,captureCheckIn:()=>c.SE,captureConsoleIntegration:()=>fs,captureEvent:()=>c.r,captureException:()=>c.Cp,captureMessage:()=>c.wd,captureSession:()=>c.J5,close:()=>c.VN,configureScope:()=>c.PN,consoleIntegration:()=>Rn,contextLinesIntegration:()=>Ln,continueTrace:()=>ve,createGetModuleFromFilename:()=>Ji,createTransport:()=>we,cron:()=>bo,debugIntegration:()=>vs,dedupeIntegration:()=>Xs,deepReadDirSync:()=>Li,defaultIntegrations:()=>zi,defaultStackParser:()=>Qi,enableAnrDetection:()=>Oi,endSession:()=>c.ky,extraErrorDataIntegration:()=>Fs,extractRequestData:()=>dt,extractTraceparentData:()=>ke,flush:()=>c.bX,functionToStringIntegration:()=>b,getActiveSpan:()=>Ve,getActiveTransaction:()=>Fe,getClient:()=>c.KU,getCurrentHub:()=>ne.BF,getCurrentScope:()=>c.o5,getDefaultIntegrations:()=>Ui,getGlobalScope:()=>Gt.m6,getHubFromCarrier:()=>ne.Me,getIsolationScope:()=>ne.rm,getModuleFromFilename:()=>go,getSentryRelease:()=>Ei,getSpanStatusFromHttpCode:()=>Je,hapiErrorPlugin:()=>ss,hapiIntegration:()=>as,httpClientIntegration:()=>js,httpIntegration:()=>si,inboundFiltersIntegration:()=>B,init:()=>xi,isInitialized:()=>c.Dp,lastEventId:()=>c.Q,linkedErrorsIntegration:()=>w,localVariablesIntegration:()=>pi,makeMain:()=>ne.gM,makeNodeTransport:()=>In,metrics:()=>nt,modulesIntegration:()=>yi,nativeNodeFetchintegration:()=>Si,nodeContextIntegration:()=>Fn,onUncaughtExceptionIntegration:()=>Ai,onUnhandledRejectionIntegration:()=>Vi,parameterize:()=>it,reportingObserverIntegration:()=>no,requestDataIntegration:()=>Ct,rewriteFramesIntegration:()=>so,runWithAsyncContext:()=>ne.fx,sessionTimingIntegration:()=>ro,setContext:()=>c.o,setCurrentClient:()=>mt,setExtra:()=>c.l7,setExtras:()=>c.cx,setHttpStatus:()=>Ue,setMeasurement:()=>yt,setTag:()=>c.NA,setTags:()=>c.Wt,setUser:()=>c.gV,spanStatusfromHttpCode:()=>ze,spotlightIntegration:()=>Yi,startActiveSpan:()=>Ae,startInactiveSpan:()=>fe,startSession:()=>c.J0,startSpan:()=>Be,startSpanManual:()=>We,startTransaction:()=>c.nb,trace:()=>Ge,trpcMiddleware:()=>Pi,withActiveSpan:()=>c.hb,withIsolationScope:()=>c.rB,withMonitor:()=>c.T$,withScope:()=>c.v4});var i={};n.r(i),n.d(i,{FunctionToString:()=>I,InboundFilters:()=>A,LinkedErrors:()=>K});var s={};n.r(s),n.d(s,{errorHandler:()=>ts,extractRequestData:()=>Mi,parseRequest:()=>Di,requestHandler:()=>$i,tracingHandler:()=>qi,trpcMiddleware:()=>ns});var o={};n.r(o),n.d(o,{Anr:()=>ji.M,Console:()=>Yn,Context:()=>kn,ContextLines:()=>jn,Hapi:()=>cs,Http:()=>oi,LocalVariables:()=>Ii,Modules:()=>Zi,OnUncaughtException:()=>Wi,OnUnhandledRejection:()=>vi,RequestData:()=>ht,Spotlight:()=>Xi,Undici:()=>Ni});var r={};n.r(r),n.d(r,{Apollo:()=>us,Express:()=>Is,GraphQL:()=>hs,Mongo:()=>Zs,Mysql:()=>Gs,Postgres:()=>Bs,Prisma:()=>As});var a=n(4022),c=n(3741),l=n(5836);let g;const d="FunctionToString",u=new WeakMap,b=(0,l._C)((()=>({name:d,setupOnce(){g=Function.prototype.toString;try{Function.prototype.toString=function(...e){const t=(0,a.sp)(this),n=u.has((0,c.KU)())&&void 0!==t?t:this;return g.apply(n,e)}}catch(e){}},setup(e){u.set(e,!0)}}))),I=(0,l.F)(d,b);var p=n(7412),C=n(6936),h=n(9653),m=n(2220);const y=[/^Script error\.?$/,/^Javascript error: Script error\.? on line 0$/,/^ResizeObserver loop completed with undelivered notifications.$/,/^Cannot redefine property: googletag$/],Z=[/^.*\/healthcheck$/,/^.*\/healthy$/,/^.*\/live$/,/^.*\/ready$/,/^.*\/heartbeat$/,/^.*\/health$/,/^.*\/healthz$/],G="InboundFilters",B=(0,l._C)(((e={})=>({name:G,setupOnce(){},processEvent(t,n,i){const s=i.getOptions(),o=function(e={},t={}){return{allowUrls:[...e.allowUrls||[],...t.allowUrls||[]],denyUrls:[...e.denyUrls||[],...t.denyUrls||[]],ignoreErrors:[...e.ignoreErrors||[],...t.ignoreErrors||[],...e.disableErrorDefaults?[]:y],ignoreTransactions:[...e.ignoreTransactions||[],...t.ignoreTransactions||[],...e.disableTransactionDefaults?[]:Z],ignoreInternal:void 0===e.ignoreInternal||e.ignoreInternal}}(e,s);return function(e,t){return t.ignoreInternal&&function(e){try{return"SentryError"===e.exception.values[0].type}catch(e){}return!1}(e)?(m.T&&p.vF.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${(0,C.$X)(e)}`),!0):function(e,t){return!(e.type||!t||!t.length)&&function(e){const t=[];let n;e.message&&t.push(e.message);try{n=e.exception.values[e.exception.values.length-1]}catch(e){}return n&&n.value&&(t.push(n.value),n.type&&t.push(`${n.type}: ${n.value}`)),m.T&&0===t.length&&p.vF.error(`Could not extract message for event ${(0,C.$X)(e)}`),t}(e).some((e=>(0,h.Xr)(e,t)))}(e,t.ignoreErrors)?(m.T&&p.vF.warn(`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${(0,C.$X)(e)}`),!0):function(e,t){if("transaction"!==e.type||!t||!t.length)return!1;const n=e.transaction;return!!n&&(0,h.Xr)(n,t)}(e,t.ignoreTransactions)?(m.T&&p.vF.warn(`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${(0,C.$X)(e)}`),!0):function(e,t){if(!t||!t.length)return!1;const n=W(e);return!!n&&(0,h.Xr)(n,t)}(e,t.denyUrls)?(m.T&&p.vF.warn(`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${(0,C.$X)(e)}.\nUrl: ${W(e)}`),!0):!function(e,t){if(!t||!t.length)return!0;const n=W(e);return!n||(0,h.Xr)(n,t)}(e,t.allowUrls)&&(m.T&&p.vF.warn(`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${(0,C.$X)(e)}.\nUrl: ${W(e)}`),!0)}(t,o)?null:t}}))),A=(0,l.F)(G,B);function W(e){try{let t;try{t=e.exception.values[0].stacktrace.frames}catch(e){}return t?function(e=[]){for(let t=e.length-1;t>=0;t--){const n=e[t];if(n&&""!==n.filename&&"[native code]"!==n.filename)return n.filename||null}return null}(t):null}catch(t){return m.T&&p.vF.error(`Cannot extract url for event ${(0,C.$X)(e)}`),null}}var f=n(3816);function V(e,t,n=250,i,s,o,r){if(!(o.exception&&o.exception.values&&r&&(0,f.tH)(r.originalException,Error)))return;const a=o.exception.values.length>0?o.exception.values[o.exception.values.length-1]:void 0;var c,l;a&&(o.exception.values=(c=v(e,t,s,r.originalException,i,o.exception.values,a,0),l=n,c.map((e=>(e.value&&(e.value=(0,h.xv)(e.value,l)),e)))))}function v(e,t,n,i,s,o,r,a){if(o.length>=n+1)return o;let c=[...o];if((0,f.tH)(i[s],Error)){R(r,a);const o=e(t,i[s]),l=c.length;Y(o,s,l,a),c=v(e,t,n,i[s],s,[o,...c],o,l)}return Array.isArray(i.errors)&&i.errors.forEach(((i,o)=>{if((0,f.tH)(i,Error)){R(r,a);const l=e(t,i),g=c.length;Y(l,`errors[${o}]`,g,a),c=v(e,t,n,i,s,[l,...c],l,g)}})),c}function R(e,t){e.mechanism=e.mechanism||{type:"generic",handled:!0},e.mechanism={...e.mechanism,..."AggregateError"===e.type&&{is_exception_group:!0},exception_id:t}}function Y(e,t,n,i){e.mechanism=e.mechanism||{type:"generic",handled:!0},e.mechanism={...e.mechanism,type:"chained",source:t,exception_id:n,parent_id:i}}var X=n(2181);function H(e,t){return e(t.stack||"",1)}function S(e,t){const n={type:t.name||t.constructor.name,value:t.message},i=H(e,t);return i.length&&(n.stacktrace={frames:i}),n}const N="LinkedErrors",w=(0,l._C)(((e={})=>{const t=e.limit||5,n=e.key||"cause";return{name:N,setupOnce(){},preprocessEvent(e,i,s){const o=s.getOptions();V(S,o.stackParser,o.maxValueLength,n,t,e,i)}}})),K=(0,l.F)(N,w),F=i,k="sentry.source",_="sentry.sample_rate",J="sentry.op",z="sentry.origin";var U=n(5644);const x=/^(?:(\w+):)\/\/(?:(\w+)(?::(\w+)?)?@)([\w.-]+)(?::(\d+))?\/(.+)/;function T(e,t=!1){const{host:n,path:i,pass:s,port:o,projectId:r,protocol:a,publicKey:c}=e;return`${a}://${c}${t&&s?`:${s}`:""}@${n}${o?`:${o}`:""}/${i?`${i}/`:i}${r}`}function E(e){return{protocol:e.protocol,publicKey:e.publicKey||"",pass:e.pass||"",host:e.host,port:e.port||"",path:e.path||"",projectId:e.projectId}}var Q=n(690);function L(e,t=[]){return[e,t]}function j(e,t){const[n,i]=e;return[n,[...i,t]]}function O(e,t){const n=e[1];for(const e of n)if(t(e,e[0].type))return!0;return!1}function P(e,t){return(t||new TextEncoder).encode(e)}function M(e,t){const[n,i]=e;let s=JSON.stringify(n);function o(e){"string"==typeof s?s="string"==typeof e?s+e:[P(s,t),e]:s.push("string"==typeof e?P(e,t):e)}for(const e of i){const[t,n]=e;if(o(`\n${JSON.stringify(t)}\n`),"string"==typeof n||n instanceof Uint8Array)o(n);else{let e;try{e=JSON.stringify(n)}catch(t){e=JSON.stringify((0,X.S8)(n))}o(e)}}return"string"==typeof s?s:function(e){const t=e.reduce(((e,t)=>e+t.length),0),n=new Uint8Array(t);let i=0;for(const t of e)n.set(t,i),i+=t.length;return n}(s)}function D(e,t){const n="string"==typeof e.data?P(e.data,t):e.data;return[(0,a.Ce)({type:"attachment",length:n.length,filename:e.filename,content_type:e.contentType,attachment_type:e.attachmentType}),n]}const q={session:"session",sessions:"session",attachment:"attachment",transaction:"transaction",event:"error",client_report:"internal",user_report:"default",profile:"profile",replay_event:"replay",replay_recording:"replay",check_in:"monitor",feedback:"feedback",span:"span",statsd:"metric_bucket"};function $(e){return q[e]}function ee(e){if(!e||!e.sdk)return;const{name:t,version:n}=e.sdk;return{name:t,version:n}}class te extends Error{constructor(e,t="warn"){super(e),this.message=e,this.name=new.target.prototype.constructor.name,Object.setPrototypeOf(this,new.target.prototype),this.logLevel=t}}var ne=n(6641);function ie(e,t,n,i){return`${e}${t}${n}${Object.entries((0,a.Ce)(i)).sort(((e,t)=>e[0].localeCompare(t[0])))}`}function se(e){return e.replace(/[^\w]+/gi,"_")}function oe(e){return e.replace(/[^\w\-.]+/gi,"_")}function re(e){return e.replace(/[^\w\-./]+/gi,"")}const ae=[["\n","\\n"],["\r","\\r"],["\t","\\t"],["\\","\\\\"],["|","\\u{7c}"],[",","\\u{2c}"]];function ce(e){const t={};for(const i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[re(i)]=(n=String(e[i]),[...n].reduce(((e,t)=>e+function(e){for(const[t,n]of ae)if(e===t)return n;return e}(t)),"")));var n;return t}var le=n(7058),ge=n(5452),de=n(9475);const ue="Not capturing exception because it's already been captured.";class be{constructor(e){if(this._options=e,this._integrations={},this._integrationsInitialized=!1,this._numProcessing=0,this._outcomes={},this._hooks={},this._eventProcessors=[],e.dsn?this._dsn=function(e){const t="string"==typeof e?function(e){const t=x.exec(e);if(!t)return void(0,p.pq)((()=>{console.error(`Invalid Sentry Dsn: ${e}`)}));const[n,i,s="",o,r="",a]=t.slice(1);let c="",l=a;const g=l.split("/");if(g.length>1&&(c=g.slice(0,-1).join("/"),l=g.pop()),l){const e=l.match(/^\d+/);e&&(l=e[0])}return E({host:o,pass:s,path:c,projectId:l,port:r,protocol:n,publicKey:i})}(e):E(e);if(t&&function(e){if(!U.T)return!0;const{port:t,projectId:n,protocol:i}=e;return!(["protocol","publicKey","host","projectId"].find((t=>!e[t]&&(p.vF.error(`Invalid Sentry Dsn: ${t} missing`),!0)))||(n.match(/^\d+$/)?function(e){return"http"===e||"https"===e}(i)?t&&isNaN(parseInt(t,10))&&(p.vF.error(`Invalid Sentry Dsn: Invalid port ${t}`),1):(p.vF.error(`Invalid Sentry Dsn: Invalid protocol ${i}`),1):(p.vF.error(`Invalid Sentry Dsn: Invalid projectId ${n}`),1)))}(t))return t}(e.dsn):m.T&&p.vF.warn("No DSN provided, client will not send events."),this._dsn){const t=function(e,t={}){const n="string"==typeof t?t:t.tunnel,i="string"!=typeof t&&t._metadata?t._metadata.sdk:void 0;return n||`${function(e){return`${function(e){const t=e.protocol?`${e.protocol}:`:"",n=e.port?`:${e.port}`:"";return`${t}//${e.host}${n}${e.path?`/${e.path}`:""}/api/`}(e)}${e.projectId}/envelope/`}(e)}?${function(e,t){return(0,a.u4)({sentry_key:e.publicKey,sentry_version:"7",...t&&{sentry_client:`${t.name}/${t.version}`}})}(e,i)}`}(this._dsn,e);this._transport=e.transport({tunnel:this._options.tunnel,recordDroppedEvent:this.recordDroppedEvent.bind(this),...e.transportOptions,url:t})}}captureException(e,t,n){if((0,C.GR)(e))return void(m.T&&p.vF.log(ue));let i=t&&t.event_id;return this._process(this.eventFromException(e,t).then((e=>this._captureEvent(e,t,n))).then((e=>{i=e}))),i}captureMessage(e,t,n,i){let s=n&&n.event_id;const o=(0,f.NF)(e)?e:String(e),r=(0,f.sO)(e)?this.eventFromMessage(o,t,n):this.eventFromException(e,n);return this._process(r.then((e=>this._captureEvent(e,n,i))).then((e=>{s=e}))),s}captureEvent(e,t,n){if(t&&t.originalException&&(0,C.GR)(t.originalException))return void(m.T&&p.vF.log(ue));let i=t&&t.event_id;const s=(e.sdkProcessingMetadata||{}).capturedSpanScope;return this._process(this._captureEvent(e,t,s||n).then((e=>{i=e}))),i}captureSession(e){"string"!=typeof e.release?m.T&&p.vF.warn("Discarded session because of missing or non-string release"):(this.sendSession(e),(0,le.qO)(e,{init:!1}))}getDsn(){return this._dsn}getOptions(){return this._options}getSdkMetadata(){return this._options._metadata}getTransport(){return this._transport}flush(e){const t=this._transport;return t?(this.metricsAggregator&&this.metricsAggregator.flush(),this._isClientDoneProcessing(e).then((n=>t.flush(e).then((e=>n&&e))))):(0,Q.XW)(!0)}close(e){return this.flush(e).then((e=>(this.getOptions().enabled=!1,this.metricsAggregator&&this.metricsAggregator.close(),e)))}getEventProcessors(){return this._eventProcessors}addEventProcessor(e){this._eventProcessors.push(e)}setupIntegrations(e){(e&&!this._integrationsInitialized||this._isEnabled()&&!this._integrationsInitialized)&&this._setupIntegrations()}init(){this._isEnabled()&&this._setupIntegrations()}getIntegrationById(e){return this.getIntegrationByName(e)}getIntegrationByName(e){return this._integrations[e]}getIntegration(e){try{return this._integrations[e.id]||null}catch(t){return m.T&&p.vF.warn(`Cannot retrieve integration ${e.id} from the current Client`),null}}addIntegration(e){const t=this._integrations[e.name];(0,l.qm)(this,e,this._integrations),t||(0,l.lc)(this,[e])}sendEvent(e,t={}){this.emit("beforeSendEvent",e,t);let n=function(e,t,n,i){const s=ee(n),o=e.type&&"replay_event"!==e.type?e.type:"event";!function(e,t){t&&(e.sdk=e.sdk||{},e.sdk.name=e.sdk.name||t.name,e.sdk.version=e.sdk.version||t.version,e.sdk.integrations=[...e.sdk.integrations||[],...t.integrations||[]],e.sdk.packages=[...e.sdk.packages||[],...t.packages||[]])}(e,n&&n.sdk);const r=function(e,t,n,i){const s=e.sdkProcessingMetadata&&e.sdkProcessingMetadata.dynamicSamplingContext;return{event_id:e.event_id,sent_at:(new Date).toISOString(),...t&&{sdk:t},...!!n&&i&&{dsn:T(i)},...s&&{trace:(0,a.Ce)({...s})}}}(e,s,i,t);return delete e.sdkProcessingMetadata,L(r,[[{type:o},e]])}(e,this._dsn,this._options._metadata,this._options.tunnel);for(const e of t.attachments||[])n=j(n,D(e,this._options.transportOptions&&this._options.transportOptions.textEncoder));const i=this._sendEnvelope(n);i&&i.then((t=>this.emit("afterSendEvent",e,t)),null)}sendSession(e){const t=function(e,t,n,i){const s=ee(n);return L({sent_at:(new Date).toISOString(),...s&&{sdk:s},...!!i&&t&&{dsn:T(t)}},["aggregates"in e?[{type:"sessions"},e]:[{type:"session"},e.toJSON()]])}(e,this._dsn,this._options._metadata,this._options.tunnel);this._sendEnvelope(t)}recordDroppedEvent(e,t,n){if(this._options.sendClientReports){const n=`${e}:${t}`;m.T&&p.vF.log(`Adding outcome: "${n}"`),this._outcomes[n]=this._outcomes[n]+1||1}}captureAggregateMetrics(e){m.T&&p.vF.log(`Flushing aggregated metrics, number of metrics: ${e.length}`);const t=function(e,t,n,i){const s={sent_at:(new Date).toISOString()};n&&n.sdk&&(s.sdk={name:n.sdk.name,version:n.sdk.version}),i&&t&&(s.dsn=T(t));const o=function(e){const t=function(e){let t="";for(const n of e){const e=Object.entries(n.tags),i=e.length>0?`|#${e.map((([e,t])=>`${e}:${t}`)).join(",")}`:"";t+=`${n.name}@${n.unit}:${n.metric}|${n.metricType}${i}|T${n.timestamp}\n`}return t}(e);return[{type:"statsd",length:t.length},t]}(e);return L(s,[o])}(e,this._dsn,this._options._metadata,this._options.tunnel);this._sendEnvelope(t)}on(e,t){this._hooks[e]||(this._hooks[e]=[]),this._hooks[e].push(t)}emit(e,...t){this._hooks[e]&&this._hooks[e].forEach((e=>e(...t)))}_setupIntegrations(){const{integrations:e}=this._options;this._integrations=(0,l.P$)(this,e),(0,l.lc)(this,e),this._integrationsInitialized=!0}_updateSessionFromEvent(e,t){let n=!1,i=!1;const s=t.exception&&t.exception.values;if(s){i=!0;for(const e of s){const t=e.mechanism;if(t&&!1===t.handled){n=!0;break}}}const o="ok"===e.status;(o&&0===e.errors||o&&n)&&((0,le.qO)(e,{...n&&{status:"crashed"},errors:e.errors||Number(i||n)}),this.captureSession(e))}_isClientDoneProcessing(e){return new Q.T2((t=>{let n=0;const i=setInterval((()=>{0==this._numProcessing?(clearInterval(i),t(!0)):(n+=1,e&&n>=e&&(clearInterval(i),t(!1)))}),1)}))}_isEnabled(){return!1!==this.getOptions().enabled&&void 0!==this._transport}_prepareEvent(e,t,n,i=(0,ne.rm)()){const s=this.getOptions(),o=Object.keys(this._integrations);return!t.integrations&&o.length>0&&(t.integrations=o),this.emit("preprocessEvent",e,t),(0,de.mG)(s,e,t,n,this,i).then((e=>{if(null===e)return e;const t={...i.getPropagationContext(),...n?n.getPropagationContext():void 0};if((!e.contexts||!e.contexts.trace)&&t){const{traceId:i,spanId:s,parentSpanId:o,dsc:r}=t;e.contexts={trace:{trace_id:i,span_id:s,parent_span_id:o},...e.contexts};const a=r||(0,ge.l)(i,this,n);e.sdkProcessingMetadata={dynamicSamplingContext:a,...e.sdkProcessingMetadata}}return e}))}_captureEvent(e,t={},n){return this._processEvent(e,t,n).then((e=>e.event_id),(e=>{if(m.T){const t=e;"log"===t.logLevel?p.vF.log(t.message):p.vF.warn(t)}}))}_processEvent(e,t,n){const i=this.getOptions(),{sampleRate:s}=i,o=pe(e),r=Ie(e),a=e.type||"error",c=`before send for type \`${a}\``;if(r&&"number"==typeof s&&Math.random()>s)return this.recordDroppedEvent("sample_rate","error",e),(0,Q.xg)(new te(`Discarding event because it's not included in the random sample (sampling rate = ${s})`,"log"));const l="replay_event"===a?"replay":a,g=(e.sdkProcessingMetadata||{}).capturedSpanIsolationScope;return this._prepareEvent(e,t,n,g).then((n=>{if(null===n)throw this.recordDroppedEvent("event_processor",l,e),new te("An event processor returned `null`, will not send event.","log");if(t.data&&!0===t.data.__sentry__)return n;const s=function(e,t,n){const{beforeSend:i,beforeSendTransaction:s}=e;return Ie(t)&&i?i(t,n):pe(t)&&s?s(t,n):t}(i,n,t);return function(e,t){const n=`${t} must return \`null\` or a valid event.`;if((0,f.Qg)(e))return e.then((e=>{if(!(0,f.Qd)(e)&&null!==e)throw new te(n);return e}),(e=>{throw new te(`${t} rejected with ${e}`)}));if(!(0,f.Qd)(e)&&null!==e)throw new te(n);return e}(s,c)})).then((i=>{if(null===i)throw this.recordDroppedEvent("before_send",l,e),new te(`${c} returned \`null\`, will not send event.`,"log");const s=n&&n.getSession();!o&&s&&this._updateSessionFromEvent(s,i);const r=i.transaction_info;if(o&&r&&i.transaction!==e.transaction){const e="custom";i.transaction_info={...r,source:e}}return this.sendEvent(i,t),i})).then(null,(e=>{if(e instanceof te)throw e;throw this.captureException(e,{data:{__sentry__:!0},originalException:e}),new te(`Event processing pipeline threw an error, original event will not be sent. Details have been sent as a new event.\nReason: ${e}`)}))}_process(e){this._numProcessing++,e.then((e=>(this._numProcessing--,e)),(e=>(this._numProcessing--,e)))}_sendEnvelope(e){if(this.emit("beforeEnvelope",e),this._isEnabled()&&this._transport)return this._transport.send(e).then(null,(e=>{m.T&&p.vF.error("Error while sending event:",e)}));m.T&&p.vF.error("Transport disabled")}_clearOutcomes(){const e=this._outcomes;return this._outcomes={},Object.keys(e).map((t=>{const[n,i]=t.split(":");return{reason:n,category:i,quantity:e[t]}}))}}function Ie(e){return void 0===e.type}function pe(e){return"transaction"===e.type}function Ce(e){const t=(0,c.KU)();t&&t.addEventProcessor&&t.addEventProcessor(e)}var he=n(6524),me=n(3445);function ye(e,t,n=()=>{}){let i;try{i=e()}catch(e){throw t(e),n(),e}return function(e,t,n){return(0,f.Qg)(e)?e.then((e=>(n(),e)),(e=>{throw t(e),n(),e})):(n(),e)}(i,t,n)}function Ze(e){if("boolean"==typeof __SENTRY_TRACING__&&!__SENTRY_TRACING__)return!1;const t=(0,c.KU)(),n=e||t&&t.getOptions();return!!n&&(n.enableTracing||"tracesSampleRate"in n||"tracesSampler"in n)}function Ge(e,t,n=()=>{},i=()=>{}){const s=(0,ne.BF)(),o=(0,c.o5)(),r=o.getSpan(),a=Ye(e),l=Re(s,{parentSpan:r,spanContext:a,forceTransaction:!1,scope:o});return o.setSpan(l),ye((()=>t(l)),(e=>{l&&l.setStatus("internal_error"),n(e,l)}),(()=>{l&&l.end(),o.setSpan(r),i()}))}function Be(e,t){const n=Ye(e);return(0,ne.fx)((()=>(0,c.v4)(e.scope,(i=>{const s=(0,ne.BF)(),o=i.getSpan(),r=e.onlyIfParent&&!o?void 0:Re(s,{parentSpan:o,spanContext:n,forceTransaction:e.forceTransaction,scope:i});return ye((()=>t(r)),(()=>{if(r){const{status:e}=(0,me.et)(r);e&&"ok"!==e||r.setStatus("internal_error")}}),(()=>r&&r.end()))}))))}const Ae=Be;function We(e,t){const n=Ye(e);return(0,ne.fx)((()=>(0,c.v4)(e.scope,(i=>{const s=(0,ne.BF)(),o=i.getSpan(),r=e.onlyIfParent&&!o?void 0:Re(s,{parentSpan:o,spanContext:n,forceTransaction:e.forceTransaction,scope:i});function a(){r&&r.end()}return ye((()=>t(r,a)),(()=>{if(r&&r.isRecording()){const{status:e}=(0,me.et)(r);e&&"ok"!==e||r.setStatus("internal_error")}}))}))))}function fe(e){if(!Ze())return;const t=Ye(e),n=(0,ne.BF)(),i=e.scope?e.scope.getSpan():Ve();if(e.onlyIfParent&&!i)return;const s=(e.scope||(0,c.o5)()).clone();return Re(n,{parentSpan:i,spanContext:t,forceTransaction:e.forceTransaction,scope:s})}function Ve(){return(0,c.o5)().getSpan()}const ve=({sentryTrace:e,baggage:t},n)=>{const i=(0,c.o5)(),{traceparentData:s,dynamicSamplingContext:o,propagationContext:r}=(0,he.E0)(e,t);i.setPropagationContext(r),m.T&&s&&p.vF.log(`[Tracing] Continuing trace ${s.traceId}.`);const l={...s,metadata:(0,a.Ce)({dynamicSamplingContext:o})};return n?(0,ne.fx)((()=>n(l))):l};function Re(e,{parentSpan:t,spanContext:n,forceTransaction:i,scope:s}){if(!Ze())return;const o=(0,ne.rm)();let r;if(t&&!i)r=t.startChild(n);else if(t){const i=(0,ge.k)(t),{traceId:s,spanId:o}=t.spanContext(),a=(0,me.pK)(t);r=e.startTransaction({traceId:s,parentSpanId:o,parentSampled:a,...n,metadata:{dynamicSamplingContext:i,...n.metadata}})}else{const{traceId:t,dsc:i,parentSpanId:a,sampled:c}={...o.getPropagationContext(),...s.getPropagationContext()};r=e.startTransaction({traceId:t,parentSpanId:a,parentSampled:c,...n,metadata:{dynamicSamplingContext:i,...n.metadata}})}return s.setSpan(r),function(e,t,n){e&&((0,a.my)(e,He,n),(0,a.my)(e,Xe,t))}(r,s,o),r}function Ye(e){if(e.startTime){const t={...e};return t.startTimestamp=(0,me.cI)(e.startTime),delete t.startTime,t}return e}const Xe="_sentryScope",He="_sentryIsolationScope";const Se=6e4;const Ne=30;function we(e,t,n=function(e){const t=[];function n(e){return t.splice(t.indexOf(e),1)[0]}return{$:t,add:function(i){if(!(void 0===e||t.lengthn(s))).then(null,(()=>n(s).then(null,(()=>{})))),s},drain:function(e){return new Q.T2(((n,i)=>{let s=t.length;if(!s)return n(!0);const o=setTimeout((()=>{e&&e>0&&n(!1)}),e);t.forEach((e=>{(0,Q.XW)(e).then((()=>{--s||(clearTimeout(o),n(!0))}),i)}))}))}}}(e.bufferSize||Ne)){let i={};function s(s){const o=[];if(O(s,((t,n)=>{const s=$(n);if(function(e,t,n=Date.now()){return function(e,t){return e[t]||e.all||0}(e,t)>n}(i,s)){const i=Ke(t,n);e.recordDroppedEvent("ratelimit_backoff",s,i)}else o.push(t)})),0===o.length)return(0,Q.XW)();const r=L(s[0],o),a=t=>{O(r,((n,i)=>{const s=Ke(n,i);e.recordDroppedEvent(t,$(i),s)}))};return n.add((()=>t({body:M(r,e.textEncoder)}).then((e=>(void 0!==e.statusCode&&(e.statusCode<200||e.statusCode>=300)&&m.T&&p.vF.warn(`Sentry responded with status code ${e.statusCode} to sent event.`),i=function(e,{statusCode:t,headers:n},i=Date.now()){const s={...e},o=n&&n["x-sentry-rate-limits"],r=n&&n["retry-after"];if(o)for(const e of o.trim().split(",")){const[t,n,,,o]=e.split(":",5),r=parseInt(t,10),a=1e3*(isNaN(r)?60:r);if(n)for(const e of n.split(";"))"metric_bucket"===e&&o&&!o.split(";").includes("custom")||(s[e]=i+a);else s.all=i+a}else r?s.all=i+function(e,t=Date.now()){const n=parseInt(`${e}`,10);if(!isNaN(n))return 1e3*n;const i=Date.parse(`${e}`);return isNaN(i)?Se:i-t}(r,i):429===t&&(s.all=i+6e4);return s}(i,e),e)),(e=>{throw a("network_error"),e})))).then((e=>e),(e=>{if(e instanceof te)return m.T&&p.vF.error("Skipped sending event because buffer is full."),a("queue_overflow"),(0,Q.XW)();throw e}))}return s.__sentry__baseTransport__=!0,{send:s,flush:e=>n.drain(e)}}function Ke(e,t){if("event"===t||"transaction"===t)return Array.isArray(e)?e[1]:void 0}function Fe(e){return(e||(0,ne.BF)()).getScope().getTransaction()}const ke=he.nc;var _e;function Je(e){if(e<400&&e>=100)return"ok";if(e>=400&&e<500)switch(e){case 401:return"unauthenticated";case 403:return"permission_denied";case 404:return"not_found";case 409:return"already_exists";case 413:return"failed_precondition";case 429:return"resource_exhausted";default:return"invalid_argument"}if(e>=500&&e<600)switch(e){case 501:return"unimplemented";case 503:return"unavailable";case 504:return"deadline_exceeded";default:return"internal_error"}return"unknown_error"}!function(e){e.Ok="ok",e.DeadlineExceeded="deadline_exceeded",e.Unauthenticated="unauthenticated",e.PermissionDenied="permission_denied",e.NotFound="not_found",e.ResourceExhausted="resource_exhausted",e.InvalidArgument="invalid_argument",e.Unimplemented="unimplemented",e.Unavailable="unavailable",e.InternalError="internal_error",e.UnknownError="unknown_error",e.Cancelled="cancelled",e.AlreadyExists="already_exists",e.FailedPrecondition="failed_precondition",e.Aborted="aborted",e.OutOfRange="out_of_range",e.DataLoss="data_loss"}(_e||(_e={}));const ze=Je;function Ue(e,t){e.setTag("http.status_code",String(t)),e.setData("http.response.status_code",t);const n=Je(t);"unknown_error"!==n&&e.setStatus(n)}const xe="c",Te="g",Ee="s",Qe="d";var Le=n(9297);const je={[xe]:class{constructor(e){this._value=e}get weight(){return 1}add(e){this._value+=e}toString(){return`${this._value}`}},[Te]:class{constructor(e){this._last=e,this._min=e,this._max=e,this._sum=e,this._count=1}get weight(){return 5}add(e){this._last=e,ethis._max&&(this._max=e),this._sum+=e,this._count++}toString(){return`${this._last}:${this._min}:${this._max}:${this._sum}:${this._count}`}},[Qe]:class{constructor(e){this._value=[e]}get weight(){return this._value.length}add(e){this._value.push(e)}toString(){return this._value.join(":")}},[Ee]:class{constructor(e){this.first=e,this._value=new Set([e])}get weight(){return this._value.size}add(e){this._value.add(e)}toString(){return Array.from(this._value).map((e=>"string"==typeof e?function(e){let t=0;for(let n=0;n>>0}(e):e)).join(":")}}};let Oe;function Pe(e){return Oe?Oe.get(e):void 0}function Me(e){const t=Pe(e);if(!t)return;const n={};for(const[,[e,i]]of t)n[e]||(n[e]=[]),n[e].push((0,a.Ce)(i));return n}function De(e,t,n,i,s,o){const r=Ve();if(r){const a=Pe(r)||new Map,c=`${e}:${t}@${i}`,l=a.get(o);if(l){const[,e]=l;a.set(o,[c,{min:Math.min(e.min,n),max:Math.max(e.max,n),count:e.count+=1,sum:e.sum+=n,tags:e.tags}])}else a.set(o,[c,{min:n,max:n,count:1,sum:n,tags:s}]);Oe||(Oe=new WeakMap),Oe.set(r,a)}}class qe{constructor(e){this._client=e,this._buckets=new Map,this._interval=setInterval((()=>this.flush()),5e3)}add(e,t,n,i="none",s={},o=(0,Le.zf)()){const r=Math.floor(o),a=oe(t),c=ce(s),l=se(i),g=ie(e,a,l,c);let d=this._buckets.get(g);const u=d&&e===Ee?d.metric.weight:0;d?(d.metric.add(n),d.timestampe));this._client.captureAggregateMetrics(e)}this._buckets.clear()}}close(){clearInterval(this._interval),this.flush()}}const $e="MetricsAggregator",et=(0,l._C)((()=>({name:$e,setupOnce(){},setup(e){e.metricsAggregator=new qe(e)}})));function tt(e,t,n,i={}){const s=(0,c.KU)(),o=(0,c.o5)();if(s){if(!s.metricsAggregator)return void(m.T&&p.vF.warn("No metrics aggregator enabled. Please add the MetricsAggregator integration to use metrics APIs"));const{unit:r,tags:a,timestamp:c}=i,{release:l,environment:g}=s.getOptions(),d=o.getTransaction(),u={};l&&(u.release=l),g&&(u.environment=g),d&&(u.transaction=(0,me.et)(d).description||""),m.T&&p.vF.log(`Adding value of ${n} to ${e} metric ${t}`),s.metricsAggregator.add(e,t,n,r,{...u,...a},c)}}const nt={increment:function(e,t=1,n){tt("c",e,t,n)},distribution:function(e,t,n){tt("d",e,t,n)},set:function(e,t,n){tt(Ee,e,t,n)},gauge:function(e,t,n){tt("g",e,t,n)},MetricsAggregator:(0,l.F)($e,et),metricsAggregatorIntegration:et};function it(e,...t){const n=new String(String.raw(e,...t));return n.__sentry_template_string__=e.join("\0").replace(/%/g,"%%").replace(/\0/g,"%s"),n.__sentry_template_values__=t,n}function st(e){return e.split(/[\?#]/,1)[0]}function ot(e){return e.split(/\\?\//).filter((e=>e.length>0&&","!==e)).length}function rt(e){const{protocol:t,host:n,path:i}=e;return`${t?`${t}://`:""}${n&&n.replace(/^.*@/,"[filtered]:[filtered]@").replace(/(:80)$/,"").replace(/(:443)$/,"")||""}${i}`}const at={ip:!1,request:!0,transaction:!0,user:!0},ct=["cookies","data","headers","method","query_string","url"],lt=["id","username","email"];function gt(e,t={}){const n=e.method&&e.method.toUpperCase();let i="",s="url";t.customRoute||e.route?(i=t.customRoute||`${e.baseUrl||""}${e.route&&e.route.path}`,s="route"):(e.originalUrl||e.url)&&(i=st(e.originalUrl||e.url||""));let o="";return t.method&&n&&(o+=n),t.method&&t.path&&(o+=" "),t.path&&i&&(o+=i),[o,s]}function dt(e,t){const{include:n=ct,deps:i}=t||{},s={},o=e.headers||{},r=e.method,a=o.host||e.hostname||e.host||"",c="https"===e.protocol||e.socket&&e.socket.encrypted?"https":"http",l=e.originalUrl||e.url||"",g=l.startsWith(c)?l:`${c}://${a}${l}`;return n.forEach((t=>{switch(t){case"headers":s.headers=o,n.includes("cookies")||delete s.headers.cookie;break;case"method":s.method=r;break;case"url":s.url=g;break;case"cookies":s.cookies=e.cookies||o.cookie&&function(e){const t={};let n=0;for(;n{e&&t in e&&(n[t]=e[t])})),n}(t.user,i.user):{};Object.keys(n).length&&(e.user={...e.user,...n})}if(i.ip){const n=t.ip||t.socket&&t.socket.remoteAddress;n&&(e.user={...e.user,ip_address:n})}return i.transaction&&!e.transaction&&(e.transaction=function(e,t){switch(t){case"path":return gt(e,{path:!0})[0];case"handler":return e.route&&e.route.stack&&e.route.stack[0]&&e.route.stack[0].name||"";default:return gt(e,{path:!0,method:!0,customRoute:e._reconstructedRoute?e._reconstructedRoute:void 0})[0]}}(t,i.transaction)),e}function bt(e,t){let n=e.originalUrl||e.url||"";if(n){n.startsWith("/")&&(n=`http://dogs.are.great${n}`);try{return e.query||"undefined"!=typeof URL&&new URL(n).search.slice(1)||t&&t.url&&t.url.parse(n).query||void 0}catch(e){return}}}const It={include:{cookies:!0,data:!0,headers:!0,ip:!1,query_string:!0,url:!0,user:{id:!0,username:!0,email:!0}},transactionNamingScheme:"methodPath"},pt="RequestData",Ct=(0,l._C)(((e={})=>{const t=ut,n={...It,...e,include:{method:!0,...It.include,...e.include,user:e.include&&"boolean"==typeof e.include.user?e.include.user:{...It.include.user,...(e.include||{}).user}}};return{name:pt,setupOnce(){},processEvent(e,i,s){const{transactionNamingScheme:o}=n,{sdkProcessingMetadata:r={}}=e,a=r.request;if(!a)return e;const c=r.requestDataOptionsFromExpressHandler||r.requestDataOptionsFromGCPWrapper||function(e){const{transactionNamingScheme:t,include:{ip:n,user:i,...s}}=e,o=[];for(const[e,t]of Object.entries(s))t&&o.push(e);let r;if(void 0===i)r=!0;else if("boolean"==typeof i)r=i;else{const e=[];for(const[t,n]of Object.entries(i))n&&e.push(t);r=e}return{include:{ip:n,user:r,request:0!==o.length?o:void 0,transaction:t}}}(n),l=t(e,a,c);if("transaction"===e.type||"handler"===o)return l;const g=a._sentryTransaction;if(g){const e=(0,me.et)(g).description||"",t="sentry.javascript.nextjs"===function(e){try{return e.getOptions()._metadata.sdk.name}catch(e){return}}(s)?e.startsWith("/api"):"path"!==o,[n]=gt(a,{path:!0,method:t,customRoute:e});l.transaction=n}return l}}})),ht=(0,l.F)(pt,Ct);function mt(e){const t=(0,ne.BF)().getStackTop();t.client=e,t.scope.setClient(e)}function yt(e,t,n){const i=Fe();i&&i.setMeasurement(e,t,n)}var Zt=n(7986),Gt=n(2486),Bt=n(2531),At=n(2786);function Wt(){const e=At.j.map((e=>{try{return e()}catch(e){return}})).filter((e=>!!e));return 0===e.length&&p.vF.warn("Performance monitoring integrations could not be automatically loaded."),e.filter((e=>!!e.loadDependency()))}const ft=require("os"),Vt=require("util");class vt{constructor(e){this._client=e,this._buckets=new Map,this._bucketsTotalWeight=0,this._interval=setInterval((()=>this._flush()),1e4),this._interval.unref&&this._interval.unref(),this._flushShift=Math.floor(1e4*Math.random()/1e3),this._forceFlush=!1}add(e,t,n,i="none",s={},o=(0,Le.zf)()){const r=Math.floor(o),a=oe(t),c=ce(s),l=se(i),g=ie(e,a,l,c);let d=this._buckets.get(g);const u=d&&e===Ee?d.metric.weight:0;d?(d.metric.add(n),d.timestamp=1e4&&this.flush()}flush(){this._forceFlush=!0,this._flush()}close(){this._forceFlush=!0,clearInterval(this._interval),this._flush()}_flush(){if(this._forceFlush)return this._forceFlush=!1,this._bucketsTotalWeight=0,this._captureMetrics(this._buckets),void this._buckets.clear();const e=Math.floor((0,Le.zf)())-10-this._flushShift,t=new Map;for(const[n,i]of this._buckets)i.timestamp<=e&&(t.set(n,i),this._bucketsTotalWeight-=i.metric.weight);for(const[e]of t)this._buckets.delete(e);this._captureMetrics(t)}_captureMetrics(e){if(e.size>0&&this._client.captureAggregateMetrics){const t=Array.from(e).map((([,e])=>e));this._client.captureAggregateMetrics(t)}}}class Rt{constructor(e,t){this._client=e,this.flushTimeout=60,this._pendingAggregates={},this._isEnabled=!0,this._intervalId=setInterval((()=>this.flush()),1e3*this.flushTimeout),this._intervalId.unref&&this._intervalId.unref(),this._sessionAttrs=t}flush(){const e=this.getSessionAggregates();0!==e.aggregates.length&&(this._pendingAggregates={},this._client.sendSession(e))}getSessionAggregates(){const e=Object.keys(this._pendingAggregates).map((e=>this._pendingAggregates[parseInt(e)])),t={attrs:this._sessionAttrs,aggregates:e};return(0,a.Ce)(t)}close(){clearInterval(this._intervalId),this._isEnabled=!1,this.flush()}incrementSessionStatusCount(){if(!this._isEnabled)return;const e=(0,c.o5)(),t=e.getRequestSession();t&&t.status&&(this._incrementSessionStatusCount(t.status,new Date),e.setRequestSession(void 0))}_incrementSessionStatusCount(e,t){const n=new Date(t).setSeconds(0,0);this._pendingAggregates[n]=this._pendingAggregates[n]||{};const i=this._pendingAggregates[n];switch(i.started||(i.started=new Date(n).toISOString()),e){case"errored":return i.errored=(i.errored||0)+1,i.errored;case"ok":return i.exited=(i.exited||0)+1,i.exited;default:return i.crashed=(i.crashed||0)+1,i.crashed}}}var Yt=n(6341),Xt=n(7930);const Ht={},St={};function Nt(e,t){Ht[e]=Ht[e]||[],Ht[e].push(t)}function wt(e,t){St[e]||(t(),St[e]=!0)}function Kt(e,t){const n=e&&Ht[e];if(n)for(const i of n)try{i(t)}catch(t){U.T&&p.vF.error(`Error while triggering instrumentation handler.\nType: ${e}\nName: ${(0,Xt.qQ)(i)}\nError:`,t)}}let Ft=null;function kt(){Ft=Yt.OW.onerror,Yt.OW.onerror=function(e,t,n,i,s){return Kt("error",{column:i,error:s,line:n,msg:e,url:t}),!(!Ft||Ft.__SENTRY_LOADER__)&&Ft.apply(this,arguments)},Yt.OW.onerror.__SENTRY_INSTRUMENTED__=!0}let _t=null;function Jt(){_t=Yt.OW.onunhandledrejection,Yt.OW.onunhandledrejection=function(e){return Kt("unhandledrejection",e),!(_t&&!_t.__SENTRY_LOADER__)||_t.apply(this,arguments)},Yt.OW.onunhandledrejection.__SENTRY_INSTRUMENTED__=!0}let zt=!1;function Ut(){const e=Fe();if(e){const t="internal_error";m.T&&p.vF.log(`[Tracing] Transaction: ${t} -> Global error occured`),e.setStatus(t)}}Ut.tag="sentry_tracingErrorCallback";var xt=n(4636);class Tt{constructor(e=1e3){this._maxlen=e,this.spans=[]}add(e){this.spans.length>this._maxlen?e.spanRecorder=void 0:this.spans.push(e)}}class Et{constructor(e={}){this._traceId=e.traceId||(0,C.eJ)(),this._spanId=e.spanId||(0,C.eJ)().substring(16),this._startTime=e.startTimestamp||(0,Le.zf)(),this.tags=e.tags?{...e.tags}:{},this.data=e.data?{...e.data}:{},this.instrumenter=e.instrumenter||"sentry",this._attributes={},this.setAttributes({[z]:e.origin||"manual",[J]:e.op,...e.attributes}),this._name=e.name||e.description,e.parentSpanId&&(this._parentSpanId=e.parentSpanId),"sampled"in e&&(this._sampled=e.sampled),e.status&&(this._status=e.status),e.endTimestamp&&(this._endTime=e.endTimestamp),void 0!==e.exclusiveTime&&(this._exclusiveTime=e.exclusiveTime),this._measurements=e.measurements?{...e.measurements}:{}}get name(){return this._name||""}set name(e){this.updateName(e)}get description(){return this._name}set description(e){this._name=e}get traceId(){return this._traceId}set traceId(e){this._traceId=e}get spanId(){return this._spanId}set spanId(e){this._spanId=e}set parentSpanId(e){this._parentSpanId=e}get parentSpanId(){return this._parentSpanId}get sampled(){return this._sampled}set sampled(e){this._sampled=e}get attributes(){return this._attributes}set attributes(e){this._attributes=e}get startTimestamp(){return this._startTime}set startTimestamp(e){this._startTime=e}get endTimestamp(){return this._endTime}set endTimestamp(e){this._endTime=e}get status(){return this._status}set status(e){this._status=e}get op(){return this._attributes[J]}set op(e){this.setAttribute(J,e)}get origin(){return this._attributes[z]}set origin(e){this.setAttribute(z,e)}spanContext(){const{_spanId:e,_traceId:t,_sampled:n}=this;return{spanId:e,traceId:t,traceFlags:n?me.aO:me.CC}}startChild(e){const t=new Et({...e,parentSpanId:this._spanId,sampled:this._sampled,traceId:this._traceId});t.spanRecorder=this.spanRecorder,t.spanRecorder&&t.spanRecorder.add(t);const n=(0,xt.z)(this);if(t.transaction=n,m.T&&n){const i=`[Tracing] Starting '${e&&e.op||"< unknown op >"}' span on transaction '${(0,me.et)(t).description||"< unknown name >"}' (${n.spanContext().spanId}).`;p.vF.log(i),this._logMessage=i}return t}setTag(e,t){return this.tags={...this.tags,[e]:t},this}setData(e,t){return this.data={...this.data,[e]:t},this}setAttribute(e,t){void 0===t?delete this._attributes[e]:this._attributes[e]=t}setAttributes(e){Object.keys(e).forEach((t=>this.setAttribute(t,e[t])))}setStatus(e){return this._status=e,this}setHttpStatus(e){return Ue(this,e),this}setName(e){this.updateName(e)}updateName(e){return this._name=e,this}isSuccess(){return"ok"===this._status}finish(e){return this.end(e)}end(e){if(this._endTime)return;const t=(0,xt.z)(this);if(m.T&&t&&t.spanContext().spanId!==this._spanId){const e=this._logMessage;e&&p.vF.log(e.replace("Starting","Finishing"))}this._endTime=(0,me.cI)(e)}toTraceparent(){return(0,me.Qh)(this)}toContext(){return(0,a.Ce)({data:this._getData(),description:this._name,endTimestamp:this._endTime,op:this.op,parentSpanId:this._parentSpanId,sampled:this._sampled,spanId:this._spanId,startTimestamp:this._startTime,status:this._status,tags:this.tags,traceId:this._traceId})}updateWithContext(e){return this.data=e.data||{},this._name=e.name||e.description,this._endTime=e.endTimestamp,this.op=e.op,this._parentSpanId=e.parentSpanId,this._sampled=e.sampled,this._spanId=e.spanId||this._spanId,this._startTime=e.startTimestamp||this._startTime,this._status=e.status,this.tags=e.tags||{},this._traceId=e.traceId||this._traceId,this}getTraceContext(){return(0,me.kX)(this)}getSpanJSON(){return(0,a.Ce)({data:this._getData(),description:this._name,op:this._attributes[J],parent_span_id:this._parentSpanId,span_id:this._spanId,start_timestamp:this._startTime,status:this._status,tags:Object.keys(this.tags).length>0?this.tags:void 0,timestamp:this._endTime,trace_id:this._traceId,origin:this._attributes[z],_metrics_summary:Me(this),profile_id:this._attributes.profile_id,exclusive_time:this._exclusiveTime,measurements:Object.keys(this._measurements).length>0?this._measurements:void 0})}isRecording(){return!this._endTime&&!!this._sampled}toJSON(){return this.getSpanJSON()}_getData(){const{data:e,_attributes:t}=this,n=Object.keys(e).length>0,i=Object.keys(t).length>0;if(n||i)return n&&i?{...e,...t}:n?e:t}}class Qt extends Et{constructor(e,t){super(e),this._contexts={},this._hub=t||(0,ne.BF)(),this._name=e.name||"",this._metadata={...e.metadata},this._trimEnd=e.trimEnd,this.transaction=this;const n=this._metadata.dynamicSamplingContext;n&&(this._frozenDynamicSamplingContext={...n})}get name(){return this._name}set name(e){this.setName(e)}get metadata(){return{source:"custom",spanMetadata:{},...this._metadata,...this._attributes[k]&&{source:this._attributes[k]},...this._attributes[_]&&{sampleRate:this._attributes[_]}}}set metadata(e){this._metadata=e}setName(e,t="custom"){this._name=e,this.setAttribute(k,t)}updateName(e){return this._name=e,this}initSpanRecorder(e=1e3){this.spanRecorder||(this.spanRecorder=new Tt(e)),this.spanRecorder.add(this)}setContext(e,t){null===t?delete this._contexts[e]:this._contexts[e]=t}setMeasurement(e,t,n=""){this._measurements[e]={value:t,unit:n}}setMetadata(e){this._metadata={...this._metadata,...e}}end(e){const t=(0,me.cI)(e),n=this._finishTransaction(t);if(n)return this._hub.captureEvent(n)}toContext(){const e=super.toContext();return(0,a.Ce)({...e,name:this._name,trimEnd:this._trimEnd})}updateWithContext(e){return super.updateWithContext(e),this._name=e.name||"",this._trimEnd=e.trimEnd,this}getDynamicSamplingContext(){return(0,ge.k)(this)}setHub(e){this._hub=e}getProfileId(){if(void 0!==this._contexts&&void 0!==this._contexts.profile)return this._contexts.profile.profile_id}_finishTransaction(e){if(void 0!==this._endTime)return;this._name||(m.T&&p.vF.warn("Transaction has no name, falling back to ``."),this._name=""),super.end(e);const t=this._hub.getClient();if(t&&t.emit&&t.emit("finishTransaction",this),!0!==this._sampled)return m.T&&p.vF.log("[Tracing] Discarding transaction because its trace was not chosen to be sampled."),void(t&&t.recordDroppedEvent("sample_rate","transaction"));const n=this.spanRecorder?this.spanRecorder.spans.filter((e=>e!==this&&(0,me.et)(e).timestamp)):[];if(this._trimEnd&&n.length>0){const e=n.map((e=>(0,me.et)(e).timestamp)).filter(Boolean);this._endTime=e.reduce(((e,t)=>e>t?e:t))}const{scope:i,isolationScope:s}={scope:this[Xe],isolationScope:this[He]};const{metadata:o}=this,{source:r}=o,c={contexts:{...this._contexts,trace:(0,me.kX)(this)},spans:n,start_timestamp:this._startTime,tags:this.tags,timestamp:this._endTime,transaction:this._name,type:"transaction",sdkProcessingMetadata:{...o,capturedSpanScope:i,capturedSpanIsolationScope:s,...(0,a.Ce)({dynamicSamplingContext:(0,ge.k)(this)})},_metrics_summary:Me(this),...r&&{transaction_info:{source:r}}};return Object.keys(this._measurements).length>0&&(m.T&&p.vF.log("[Measurements] Adding measurements to transaction",JSON.stringify(this._measurements,void 0,2)),c.measurements=this._measurements),m.T&&p.vF.log(`[Tracing] Finishing ${this.op} transaction: ${this._name}.`),c}}function Lt(){const e=this.getScope().getSpan();return e?{"sentry-trace":(0,me.Qh)(e)}:{}}function jt(e,t){const n=this.getClient(),i=n&&n.getOptions()||{},s=i.instrumenter||"sentry",o=e.instrumenter||"sentry";s!==o&&(m.T&&p.vF.error(`A transaction was started with instrumenter=\`${o}\`, but the SDK is configured with the \`${s}\` instrumenter.\nThe transaction will not be sampled. Please use the ${s} instrumentation to start transactions.`),e.sampled=!1);let r=new Qt(e,this);return r=function(e,t,n){if(!Ze(t))return e.sampled=!1,e;if(void 0!==e.sampled)return e.setAttribute(_,Number(e.sampled)),e;let i;return"function"==typeof t.tracesSampler?(i=t.tracesSampler(n),e.setAttribute(_,Number(i))):void 0!==n.parentSampled?i=n.parentSampled:void 0!==t.tracesSampleRate?(i=t.tracesSampleRate,e.setAttribute(_,Number(i))):(i=1,e.setAttribute(_,i)),s=i,((0,f.yr)(s)||"number"!=typeof s&&"boolean"!=typeof s?(m.T&&p.vF.warn(`[Tracing] Given sample rate is invalid. Sample rate must be a boolean or a number between 0 and 1. Got ${JSON.stringify(s)} of type ${JSON.stringify(typeof s)}.`),0):!(s<0||s>1)||(m.T&&p.vF.warn(`[Tracing] Given sample rate is invalid. Sample rate must be between 0 and 1. Got ${s}.`),0))?i?(e.sampled=Math.random()0){const e=n.getRequestSession();e&&"ok"===e.status&&(e.status="errored")}return super.captureEvent(e,t,n)}close(e){return this._sessionFlusher&&this._sessionFlusher.close(),super.close(e)}initSessionFlusher(){const{release:e,environment:t}=this._options;e?this._sessionFlusher=new Rt(this,{release:e,environment:t}):m.T&&p.vF.warn("Cannot initialise an instance of SessionFlusher if no release is provided!")}captureCheckIn(e,t,n){const i="checkInId"in e&&e.checkInId?e.checkInId:(0,C.eJ)();if(!this._isEnabled())return m.T&&p.vF.warn("SDK not enabled, will not capture checkin."),i;const s=this.getOptions(),{release:o,environment:r,tunnel:c}=s,l={check_in_id:i,monitor_slug:e.monitorSlug,status:e.status,release:o,environment:r};"duration"in e&&(l.duration=e.duration),t&&(l.monitor_config={schedule:t.schedule,checkin_margin:t.checkinMargin,max_runtime:t.maxRuntime,timezone:t.timezone});const[g,d]=this._getTraceInfoFromScope(n);d&&(l.contexts={trace:d});const u=function(e,t,n,i,s){const o={sent_at:(new Date).toISOString()};n&&n.sdk&&(o.sdk={name:n.sdk.name,version:n.sdk.version}),i&&s&&(o.dsn=T(s)),t&&(o.trace=(0,a.Ce)(t));const r=function(e){return[{type:"check_in"},e]}(e);return L(o,[r])}(l,g,this.getSdkMetadata(),c,this.getDsn());return m.T&&p.vF.info("Sending checkin:",e.monitorSlug,e.status),this._sendEnvelope(u),i}_captureRequestSession(){this._sessionFlusher?this._sessionFlusher.incrementSessionStatusCount():m.T&&p.vF.warn("Discarded request mode session because autoSessionTracking option was disabled")}_prepareEvent(e,t,n,i){return this._options.platform&&(e.platform=e.platform||this._options.platform),this._options.runtime&&(e.contexts={...e.contexts,runtime:(e.contexts||{}).runtime||this._options.runtime}),this._options.serverName&&(e.server_name=e.server_name||this._options.serverName),super._prepareEvent(e,t,n,i)}_getTraceInfoFromScope(e){if(!e)return[void 0,void 0];const t=e.getSpan();if(t)return[(0,xt.z)(t)?(0,ge.k)(t):void 0,(0,me.kX)(t)];const{traceId:n,spanId:i,parentSpanId:s,dsc:o}=e.getPropagationContext(),r={trace_id:n,span_id:i,parent_span_id:s};return o?[o,r]:[(0,ge.l)(n,this,e),r]}}class Pt extends Ot{constructor(e){!function(e,t,n=[t],i="npm"){const s=e._metadata||{};s.sdk||(s.sdk={name:`sentry.javascript.${t}`,packages:n.map((e=>({name:`${i}:@sentry/${e}`,version:Zt.M}))),version:Zt.M}),e._metadata=s}(e,"node"),e.transportOptions={textEncoder:new Vt.TextEncoder,...e.transportOptions},super({...e,platform:"node",runtime:{name:"node",version:global.process.version},serverName:e.serverName||global.process.env.SENTRY_NAME||ft.hostname()})}}function Mt(e,t){return null!=e?e:t()}var Dt=n(8611),qt=n(5692),$t=n(2203),en=n(7016);const tn=require("zlib");var nn=n(853),sn=n(9278);const on=require("tls"),rn=Symbol("AgentBaseInternalState");class an extends Dt.Agent{constructor(e){super(e),this[rn]={}}isSecureEndpoint(e){if(e){if("boolean"==typeof e.secureEndpoint)return e.secureEndpoint;if("string"==typeof e.protocol)return"https:"===e.protocol}const{stack:t}=new Error;return"string"==typeof t&&t.split("\n").some((e=>-1!==e.indexOf("(https.js:")||-1!==e.indexOf("node:https:")))}createSocket(e,t,n){const i={...t,secureEndpoint:this.isSecureEndpoint(t)};Promise.resolve().then((()=>this.connect(e,i))).then((s=>{if(s instanceof Dt.Agent)return s.addRequest(e,i);this[rn].currentSocket=s,super.createSocket(e,t,n)}),n)}createConnection(){const e=this[rn].currentSocket;if(this[rn].currentSocket=void 0,!e)throw new Error("No socket was returned in the `connect()` function");return e}get defaultPort(){return Mt(this[rn].defaultPort,(()=>"https:"===this.protocol?443:80))}set defaultPort(e){this[rn]&&(this[rn].defaultPort=e)}get protocol(){return Mt(this[rn].protocol,(()=>this.isSecureEndpoint()?"https:":"http:"))}set protocol(e){this[rn]&&(this[rn].protocol=e)}}function cn(...e){p.vF.log("[https-proxy-agent:parse-proxy-response]",...e)}function ln(...e){p.vF.log("[https-proxy-agent]",...e)}class gn extends an{static __initStatic(){this.protocols=["http","https"]}constructor(e,t){super(t),this.options={},this.proxy="string"==typeof e?new en.URL(e):e,this.proxyHeaders=Mt((0,nn.z)([t,"optionalAccess",e=>e.headers]),(()=>({}))),ln("Creating new HttpsProxyAgent instance: %o",this.proxy.href);const n=(this.proxy.hostname||this.proxy.host).replace(/^\[|\]$/g,""),i=this.proxy.port?parseInt(this.proxy.port,10):"https:"===this.proxy.protocol?443:80;this.connectOpts={ALPNProtocols:["http/1.1"],...t?un(t,"headers"):null,host:n,port:i}}async connect(e,t){const{proxy:n}=this;if(!t.host)throw new TypeError('No "host" provided');let i;if("https:"===n.protocol){ln("Creating `tls.Socket`: %o",this.connectOpts);const e=this.connectOpts.servername||this.connectOpts.host;i=on.connect({...this.connectOpts,servername:e&&sn.isIP(e)?void 0:e})}else ln("Creating `net.Socket`: %o",this.connectOpts),i=sn.connect(this.connectOpts);const s="function"==typeof this.proxyHeaders?this.proxyHeaders():{...this.proxyHeaders},o=sn.isIPv6(t.host)?`[${t.host}]`:t.host;let r=`CONNECT ${o}:${t.port} HTTP/1.1\r\n`;if(n.username||n.password){const e=`${decodeURIComponent(n.username)}:${decodeURIComponent(n.password)}`;s["Proxy-Authorization"]=`Basic ${Buffer.from(e).toString("base64")}`}s.Host=`${o}:${t.port}`,s["Proxy-Connection"]||(s["Proxy-Connection"]=this.keepAlive?"Keep-Alive":"close");for(const e of Object.keys(s))r+=`${e}: ${s[e]}\r\n`;const a=function(e){return new Promise(((t,n)=>{let i=0;const s=[];function o(){const a=e.read();a?function(a){s.push(a),i+=a.length;const c=Buffer.concat(s,i),l=c.indexOf("\r\n\r\n");if(-1===l)return cn("have not received end of HTTP headers yet..."),void o();const g=c.slice(0,l).toString("ascii").split("\r\n"),d=g.shift();if(!d)return e.destroy(),n(new Error("No header received from proxy CONNECT response"));const u=d.split(" "),b=+u[1],I=u.slice(2).join(" "),p={};for(const t of g){if(!t)continue;const i=t.indexOf(":");if(-1===i)return e.destroy(),n(new Error(`Invalid header from proxy CONNECT response: "${t}"`));const s=t.slice(0,i).toLowerCase(),o=t.slice(i+1).trimStart(),r=p[s];"string"==typeof r?p[s]=[r,o]:Array.isArray(r)?r.push(o):p[s]=o}cn("got proxy server response: %o %o",d,p),r(),t({connect:{statusCode:b,statusText:I,headers:p},buffered:c})}(a):e.once("readable",o)}function r(){e.removeListener("end",a),e.removeListener("error",c),e.removeListener("readable",o)}function a(){r(),cn("onend"),n(new Error("Proxy connection ended before receiving CONNECT response"))}function c(e){r(),cn("onerror %o",e),n(e)}e.on("error",c),e.on("end",a),o()}))}(i);i.write(`${r}\r\n`);const{connect:c,buffered:l}=await a;if(e.emit("proxyConnect",c),this.emit("proxyConnect",c,e),200===c.statusCode){if(e.once("socket",dn),t.secureEndpoint){ln("Upgrading socket connection to TLS");const e=t.servername||t.host;return on.connect({...un(t,"host","path","port"),socket:i,servername:sn.isIP(e)?void 0:e})}return i}i.destroy();const g=new sn.Socket({writable:!1});return g.readable=!0,e.once("socket",(e=>{ln("Replaying proxy buffer for failed request"),e.push(l),e.push(null)})),g}}function dn(e){e.resume()}function un(e,...t){const n={};let i;for(i in e)t.includes(i)||(n[i]=e[i]);return n}gn.__initStatic();const bn=32768;function In(e){let t;try{t=new en.URL(e.url)}catch(t){return(0,p.pq)((()=>{console.warn("[@sentry/node]: Invalid dsn or tunnel option, will not send any events. The tunnel option must be a full URL when used.")})),we(e,(()=>Promise.resolve({})))}const n="https:"===t.protocol,i=function(e,t){const{no_proxy:n}=process.env;return n&&n.split(",").some((t=>e.host.endsWith(t)||e.hostname.endsWith(t)))?void 0:t}(t,e.proxy||(n?process.env.https_proxy:void 0)||process.env.http_proxy),s=n?qt:Dt,o=void 0!==e.keepAlive&&e.keepAlive,r=i?new gn(i):new s.Agent({keepAlive:o,maxSockets:30,timeout:2e3}),a=function(e,t,n){const{hostname:i,pathname:s,port:o,protocol:r,search:a}=new en.URL(e.url);return function(c){return new Promise(((l,g)=>{let d=function(e){return new $t.Readable({read(){this.push(e),this.push(null)}})}(c.body);const u={...e.headers};c.body.length>bn&&(u["content-encoding"]="gzip",d=d.pipe((0,tn.createGzip)()));const b=t.request({method:"POST",agent:n,headers:u,hostname:i,path:`${s}${a}`,port:o,protocol:r,ca:e.caCerts},(e=>{e.on("data",(()=>{})),e.on("end",(()=>{})),e.setEncoding("utf8");const t=Mt(e.headers["retry-after"],(()=>null)),n=Mt(e.headers["x-sentry-rate-limits"],(()=>null));l({statusCode:e.statusCode,headers:{"retry-after":t,"x-sentry-rate-limits":Array.isArray(n)?n[0]:n}})}));b.on("error",g),d.pipe(b)}))}}(e,Mt(e.httpModule,(()=>s)),r);return we(e,a)}var pn=n(3245);const Cn=require("domain");function hn(){return Cn.active}function mn(){const e=hn();if(e)return(0,ne.TF)(e),(0,ne.Me)(e)}function yn(e,t){const n=hn();if(n&&(0,nn.z)([t,"optionalAccess",e=>e.reuseExisting]))return e();const i=Cn.create(),s=function(e){const t={};return(0,ne.TF)(t,e),(0,ne.Me)(t)}(n?(0,ne.Me)(n):void 0);return(0,ne.lq)(i,s),i.bind((()=>e()))()}const Zn=require("async_hooks");let Gn;function Bn(){pn.S.major>=14?function(){function e(){return Gn.getStore()}Gn||(Gn=new Zn.AsyncLocalStorage),(0,ne.nX)({getCurrentHub:e,runWithAsyncContext:function(t,n){const i=e();if(i&&(0,nn.z)([n,"optionalAccess",e=>e.reuseExisting]))return t();const s=function(e){const t={};return(0,ne.TF)(t,e),(0,ne.Me)(t)}(i);return Gn.run(s,(()=>t()))}})}():(0,ne.nX)({getCurrentHub:mn,runWithAsyncContext:yn})}function An(e){const t="console";Nt(t,e),wt(t,Wn)}function Wn(){"console"in Yt.OW&&p.Ow.forEach((function(e){e in Yt.OW.console&&(0,a.GS)(Yt.OW.console,e,(function(t){return p.Z9[e]=t,function(...t){Kt("console",{args:t,level:e});const n=p.Z9[e];n&&n.apply(Yt.OW.console,t)}}))}))}const fn=["fatal","error","warning","log","info","debug"];function Vn(e){return"warn"===e?"warning":fn.includes(e)?e:"log"}const vn="Console",Rn=(0,l._C)((()=>({name:vn,setupOnce(){},setup(e){An((({args:t,level:n})=>{(0,c.KU)()===e&&(0,c.ZQ)({category:"console",level:Vn(n),message:Vt.format.apply(void 0,t)},{input:[...t],level:n})}))}}))),Yn=(0,l.F)(vn,Rn),Xn=require("child_process"),Hn=require("fs");var Sn=n(6928);const Nn=(0,Vt.promisify)(Hn.readFile),wn=(0,Vt.promisify)(Hn.readdir),Kn="Context",Fn=(0,l._C)(((e={})=>{let t;const n={app:!0,os:!0,device:!0,culture:!0,cloudResource:!0,...e};return{name:Kn,setupOnce(){},processEvent:e=>async function(e){void 0===t&&(t=async function(){const e={};if(n.os&&(e.os=await async function(){const e=ft.platform();switch(e){case"darwin":return async function(){const e={kernel_version:ft.release(),name:"Mac OS X",version:"10."+(Number(ft.release().split(".")[0])-4)};try{const t=await new Promise(((e,t)=>{(0,Xn.execFile)("/usr/bin/sw_vers",((n,i)=>{n?t(n):e(i)}))}));e.name=Un(/^ProductName:\s+(.*)$/m,t),e.version=Un(/^ProductVersion:\s+(.*)$/m,t),e.build=Un(/^BuildVersion:\s+(.*)$/m,t)}catch(e){}return e}();case"linux":return async function(){const e={kernel_version:ft.release(),name:"Linux"};try{const t=await wn("/etc"),n=Jn.find((e=>t.includes(e.name)));if(!n)return e;const i=(0,Sn.join)("/etc",n.name),s=(await Nn(i,{encoding:"utf-8"})).toLowerCase(),{distros:o}=n;e.name=o.find((e=>s.indexOf(xn(e))>=0))||o[0];const r=xn(e.name);e.version=zn[r](s)}catch(e){}return e}();default:return{name:_n[e]||e,version:ft.release()}}}()),n.app&&(e.app=function(){const e=process.memoryUsage().rss;return{app_start_time:new Date(Date.now()-1e3*process.uptime()).toISOString(),app_memory:e}}()),n.device&&(e.device=function(e){const t={};let n;try{n=ft.uptime&&ft.uptime()}catch(e){}if("number"==typeof n&&(t.boot_time=new Date(Date.now()-1e3*n).toISOString()),t.arch=ft.arch(),(!0===e||e.memory)&&(t.memory_size=ft.totalmem(),t.free_memory=ft.freemem()),!0===e||e.cpu){const e=ft.cpus();if(e&&e.length){const n=e[0];t.processor_count=e.length,t.cpu_description=n.model,t.processor_frequency=n.speed}}return t}(n.device)),n.culture){const t=function(){try{if("string"!=typeof process.versions.icu)return;const e=new Date(9e8);if("enero"===new Intl.DateTimeFormat("es",{month:"long"}).format(e)){const e=Intl.DateTimeFormat().resolvedOptions();return{locale:e.locale,timezone:e.timeZone}}}catch(e){}}();t&&(e.culture=t)}return n.cloudResource&&(e.cloud_resource=process.env.VERCEL?{"cloud.provider":"vercel","cloud.region":process.env.VERCEL_REGION}:process.env.AWS_REGION?{"cloud.provider":"aws","cloud.region":process.env.AWS_REGION,"cloud.platform":process.env.AWS_EXECUTION_ENV}:process.env.GCP_PROJECT?{"cloud.provider":"gcp"}:process.env.ALIYUN_REGION_ID?{"cloud.provider":"alibaba_cloud","cloud.region":process.env.ALIYUN_REGION_ID}:process.env.WEBSITE_SITE_NAME&&process.env.REGION_NAME?{"cloud.provider":"azure","cloud.region":process.env.REGION_NAME}:process.env.IBM_CLOUD_REGION?{"cloud.provider":"ibm_cloud","cloud.region":process.env.IBM_CLOUD_REGION}:process.env.TENCENTCLOUD_REGION?{"cloud.provider":"tencent_cloud","cloud.region":process.env.TENCENTCLOUD_REGION,"cloud.account.id":process.env.TENCENTCLOUD_APPID,"cloud.availability_zone":process.env.TENCENTCLOUD_ZONE}:process.env.NETLIFY?{"cloud.provider":"netlify"}:process.env.FLY_REGION?{"cloud.provider":"fly.io","cloud.region":process.env.FLY_REGION}:process.env.DYNO?{"cloud.provider":"heroku"}:void 0),e}());const i=(s=await t,(0,nn.z)([s,"optionalAccess",e=>e.app,"optionalAccess",e=>e.app_memory])&&(s.app.app_memory=process.memoryUsage().rss),(0,nn.z)([s,"optionalAccess",e=>e.device,"optionalAccess",e=>e.free_memory])&&(s.device.free_memory=ft.freemem()),s);var s;return e.contexts={...e.contexts,app:{...i.app,...(0,nn.z)([e,"access",e=>e.contexts,"optionalAccess",e=>e.app])},os:{...i.os,...(0,nn.z)([e,"access",e=>e.contexts,"optionalAccess",e=>e.os])},device:{...i.device,...(0,nn.z)([e,"access",e=>e.contexts,"optionalAccess",e=>e.device])},culture:{...i.culture,...(0,nn.z)([e,"access",e=>e.contexts,"optionalAccess",e=>e.culture])},cloud_resource:{...i.cloud_resource,...(0,nn.z)([e,"access",e=>e.contexts,"optionalAccess",e=>e.cloud_resource])}},e}(e)}})),kn=(0,l.F)(Kn,Fn),_n={aix:"IBM AIX",freebsd:"FreeBSD",openbsd:"OpenBSD",sunos:"SunOS",win32:"Windows"},Jn=[{name:"fedora-release",distros:["Fedora"]},{name:"redhat-release",distros:["Red Hat Linux","Centos"]},{name:"redhat_version",distros:["Red Hat Linux"]},{name:"SuSE-release",distros:["SUSE Linux"]},{name:"lsb-release",distros:["Ubuntu Linux","Arch Linux"]},{name:"debian_version",distros:["Debian"]},{name:"debian_release",distros:["Debian"]},{name:"arch-release",distros:["Arch Linux"]},{name:"gentoo-release",distros:["Gentoo Linux"]},{name:"novell-release",distros:["SUSE Linux"]},{name:"alpine-release",distros:["Alpine Linux"]}],zn={alpine:e=>e,arch:e=>Un(/distrib_release=(.*)/,e),centos:e=>Un(/release ([^ ]+)/,e),debian:e=>e,fedora:e=>Un(/release (..)/,e),mint:e=>Un(/distrib_release=(.*)/,e),red:e=>Un(/release ([^ ]+)/,e),suse:e=>Un(/VERSION = (.*)\n/,e),ubuntu:e=>Un(/distrib_release=(.*)/,e)};function Un(e,t){const n=e.exec(t);return n?n[1]:void 0}function xn(e){return e.split(" ")[0].toLowerCase()}class Tn{constructor(e){this._maxSize=e,this._cache=new Map}get size(){return this._cache.size}get(e){const t=this._cache.get(e);if(void 0!==t)return this._cache.delete(e),this._cache.set(e,t),t}set(e,t){this._cache.size>=this._maxSize&&this._cache.delete(this._cache.keys().next().value),this._cache.set(e,t)}remove(e){const t=this._cache.get(e);return t&&this._cache.delete(e),t}clear(){this._cache.clear()}keys(){return Array.from(this._cache.keys())}values(){const e=[];return this._cache.forEach((t=>e.push(t))),e}}const En=new Tn(100),Qn="ContextLines",Ln=(0,l._C)(((e={})=>{const t=void 0!==e.frameContextLines?e.frameContextLines:7;return{name:Qn,setupOnce(){},processEvent:e=>async function(e,t){const n={},i=[];if(t>0&&(0,nn.z)([e,"access",e=>e.exception,"optionalAccess",e=>e.values]))for(const t of e.exception.values)if((0,nn.z)([t,"access",e=>e.stacktrace,"optionalAccess",e=>e.frames]))for(let e=t.stacktrace.frames.length-1;e>=0;e--){const s=t.stacktrace.frames[e];!s.filename||n[s.filename]||En.get(s.filename)||(i.push(Pn(s.filename)),n[s.filename]=1)}if(i.length>0&&await Promise.all(i),t>0&&(0,nn.z)([e,"access",e=>e.exception,"optionalAccess",e=>e.values]))for(const n of e.exception.values)n.stacktrace&&n.stacktrace.frames&&await On(n.stacktrace.frames,t);return e}(e,t)}})),jn=(0,l.F)(Qn,Ln);function On(e,t){for(const n of e)if(n.filename&&void 0===n.context_line){const e=En.get(n.filename);if(e)try{(0,C.db)(e,n,t)}catch(e){}}}async function Pn(e){const t=En.get(e);if(null===t)return null;if(void 0!==t)return t;let n=null;try{const t=await(i=e,new Promise(((e,t)=>{(0,Hn.readFile)(i,"utf8",((n,i)=>{n?t(n):e(i)}))})));n=t.split("\n")}catch(e){}var i;return En.set(e,n),n}function Mn(e,t){const n=t&&function(e){return void 0!==e.getClient}(t)?t.getClient():t,i=n&&n.getDsn(),s=n&&n.getOptions().tunnel;return function(e,t){return!!t&&e.includes(t.host)}(e,i)||function(e,t){return!!t&&Dn(e)===Dn(t)}(e,s)}function Dn(e){return"/"===e[e.length-1]?e.slice(0,-1):e}var qn=n(5584);const $n="undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__;function ei(e){const{protocol:t,hostname:n,port:i}=ii(e),s=e.pathname||"/";return`${t}//${e.auth?function(e){const[t,n]=e.split(":");return`${t?"[Filtered]":""}:${n?"[Filtered]":""}@`}(e.auth):""}${n}${i}${s}`}function ti(e,t,n){if(!e)return e;let[i,s]=e.split(" ");return t.host&&!t.protocol&&(t.protocol=(0,nn.z)([n,"optionalAccess",e=>e.agent,"optionalAccess",e=>e.protocol]),s=ei(t)),(0,nn.z)([s,"optionalAccess",e=>e.startsWith,"call",e=>e("///")])&&(s=s.slice(2)),`${i} ${s}`}function ni(e){const t={protocol:e.protocol,hostname:"string"==typeof e.hostname&&e.hostname.startsWith("[")?e.hostname.slice(1,-1):e.hostname,hash:e.hash,search:e.search,pathname:e.pathname,path:`${e.pathname||""}${e.search||""}`,href:e.href};return""!==e.port&&(t.port=Number(e.port)),(e.username||e.password)&&(t.auth=`${e.username}:${e.password}`),t}function ii(e){const t=e.protocol||"",n=e.hostname||e.host||"";return{protocol:t,hostname:n,port:!e.port||80===e.port||443===e.port||/^(.*):(\d+)$/.test(n)?"":`:${e.port}`}}const si=(0,l._C)(((e={})=>{const{breadcrumbs:t,tracing:n,shouldCreateSpanForRequest:i}=e,s={breadcrumbs:t,tracing:!1!==n&&(0,a.Ce)({enableIfHasTracingEnabled:!0!==n||void 0,shouldCreateSpanForRequest:i})};return new oi(s)}));class oi{static __initStatic(){this.id="Http"}__init(){this.name=oi.id}constructor(e={}){oi.prototype.__init.call(this),this._breadcrumbs=void 0===e.breadcrumbs||e.breadcrumbs,this._tracing=e.tracing?!0===e.tracing?{}:e.tracing:void 0}setupOnce(e,t){const i=(0,nn.z)([t,"call",e=>e(),"access",e=>e.getClient,"call",e=>e(),"optionalAccess",e=>e.getOptions,"call",e=>e()]),s=function(e,t){return void 0!==e&&(!e.enableIfHasTracingEnabled||Ze(t))}(this._tracing,i);if(!this._breadcrumbs&&!s)return;if(i&&"sentry"!==i.instrumenter)return void($n&&p.vF.log("HTTP Integration is skipped because of instrumenter configuration."));const o=function(e,t,n){return e?(0,nn.z)([t,"optionalAccess",e=>e.shouldCreateSpanForRequest])||(0,nn.z)([n,"optionalAccess",e=>e.shouldCreateSpanForRequest]):()=>!1}(s,this._tracing,i),r=(0,nn.z)([i,"optionalAccess",e=>e.tracePropagationTargets])||(0,nn.z)([this,"access",e=>e._tracing,"optionalAccess",e=>e.tracePropagationTargets]),c=n(8611),l=ri(c,this._breadcrumbs,o,r);if((0,a.GS)(c,"get",l),(0,a.GS)(c,"request",l),pn.S.major>8){const e=n(5692),t=ri(e,this._breadcrumbs,o,r);(0,a.GS)(e,"get",t),(0,a.GS)(e,"request",t)}}}function ri(e,t,n,i){const s=new Tn(100),o=new Tn(100);function r(e,t,n,i){(0,ne.BF)().getIntegration(oi)&&(0,c.ZQ)({category:"http",data:{status_code:i&&i.statusCode,...t},type:"http"},{event:e,request:n,response:i})}return function(a){return function(...l){const g=function(e,t){let n,i;if("function"==typeof t[t.length-1]&&(n=t.pop()),"string"==typeof t[0])i=ni(new en.URL(t[0]));else if(t[0]instanceof en.URL)i=ni(t[0]);else{i=t[0];try{const e=new en.URL(i.path||"",`${i.protocol||"http:"}//${i.hostname}`);i={pathname:e.pathname,search:e.search,hash:e.hash,...i}}catch(e){}}return 2===t.length&&(i={...i,...t[1]}),void 0===i.protocol&&(pn.S.major>8?i.protocol=(0,nn.z)([(0,nn.z)([e,"optionalAccess",e=>e.globalAgent]),"optionalAccess",e=>e.protocol])||(0,nn.z)([i.agent,"optionalAccess",e=>e.protocol])||(0,nn.z)([i._defaultAgent,"optionalAccess",e=>e.protocol]):i.protocol=(0,nn.z)([i.agent,"optionalAccess",e=>e.protocol])||(0,nn.z)([i._defaultAgent,"optionalAccess",e=>e.protocol])||(0,nn.z)([(0,nn.z)([e,"optionalAccess",e=>e.globalAgent]),"optionalAccess",e=>e.protocol])),n?[i,n]:[i]}(e,l),d=g[0],u=function(e){const{protocol:t,hostname:n,port:i}=ii(e);return`${t}//${n}${i}${e.path?e.path:"/"}`}(d),b=ei(d),I=(0,c.KU)();if(Mn(b,I))return a.apply(e,g);const C=(0,c.o5)(),m=(0,ne.rm)(),y=Ve(),Z=function(e,t){const n={url:e,"http.method":t.method||"GET"};return t.hash&&(n["http.fragment"]=t.hash.substring(1)),t.search&&(n["http.query"]=t.search.substring(1)),n}(b,d),G=(e=>{if(void 0===n)return!0;const t=s.get(e);if(void 0!==t)return t;const i=n(e);return s.set(e,i),i})(u)?(0,nn.z)([y,"optionalAccess",e=>e.startChild,"call",e=>e({op:"http.client",origin:"auto.http.node.http",description:`${Z["http.method"]} ${Z.url}`,data:Z})]):void 0;if(I&&(e=>{if(void 0===i)return!0;const t=o.get(e);if(void 0!==t)return t;const n=(0,h.Xr)(e,i);return o.set(e,n),n})(u)){const{traceId:e,spanId:t,sampled:n,dsc:i}={...m.getPropagationContext(),...C.getPropagationContext()},s=G?(0,me.Qh)(G):(0,he.TC)(e,t,n),o=(0,qn.De)(i||(G?(0,ge.k)(G):(0,ge.l)(e,I,C)));!function(e,t,n,i){(e.headers||{})["sentry-trace"]||($n&&p.vF.log(`[Tracing] Adding sentry-trace header ${n} to outgoing request to "${t}": `),e.headers={...e.headers,"sentry-trace":n,...i&&i.length>0&&{baggage:ai(e,i)}})}(d,b,s,o)}else $n&&p.vF.log(`[Tracing] Not adding sentry-trace header to outgoing request (${b}) due to mismatching tracePropagationTargets option.`);return a.apply(e,g).once("response",(function(e){t&&r("response",Z,this,e),G&&(e.statusCode&&Ue(G,e.statusCode),G.updateName(ti((0,me.et)(G).description||"",d,this)||""),G.end())})).once("error",(function(){t&&r("error",Z,this),G&&(Ue(G,500),G.updateName(ti((0,me.et)(G).description||"",d,this)||""),G.end())}))}}}function ai(e,t){return e.headers&&e.headers.baggage?t?Array.isArray(e.headers.baggage)?[...e.headers.baggage,t]:[e.headers.baggage,t]:e.headers.baggage:t}function ci(e){return void 0!==e&&(0===e.length||"?"===e||""===e)}function li(e){if(void 0!==e)return e.slice(-10).reduce(((e,t)=>`${e},${t.function},${t.lineno},${t.colno}`),"")}function gi(e){let t=[],n=!1;function i(i){t=[],n||(n=!0,e(i))}return t.push(i),{add:function(e){t.push(e)},next:function(e){const n=t.pop()||i;try{n(e)}catch(t){i(e)}}}}oi.__initStatic();class di{constructor(){const{Session:e}=n(264);this._session=new e}configureAndConnect(e,t){this._session.connect(),this._session.on("Debugger.paused",(t=>{e(t,(()=>{this._session.post("Debugger.resume")}))})),this._session.post("Debugger.enable"),this._session.post("Debugger.setPauseOnExceptions",{state:t?"all":"uncaught"})}setPauseOnExceptions(e){this._session.post("Debugger.setPauseOnExceptions",{state:e?"all":"uncaught"})}getLocalVariables(e,t){this._getProperties(e,(e=>{const{add:n,next:i}=gi(t);for(const t of e)if((0,nn.z)([t,"optionalAccess",e=>e.value,"optionalAccess",e=>e.objectId])&&"Array"===(0,nn.z)([t,"optionalAccess",e=>e.value,"access",e=>e.className])){const e=t.value.objectId;n((n=>this._unrollArray(e,t.name,n,i)))}else if((0,nn.z)([t,"optionalAccess",e=>e.value,"optionalAccess",e=>e.objectId])&&"Object"===(0,nn.z)([t,"optionalAccess",e=>e.value,"optionalAccess",e=>e.className])){const e=t.value.objectId;n((n=>this._unrollObject(e,t.name,n,i)))}else null==(0,nn.z)([t,"optionalAccess",e=>e.value,"optionalAccess",e=>e.value])&&null==(0,nn.z)([t,"optionalAccess",e=>e.value,"optionalAccess",e=>e.description])||n((e=>this._unrollOther(t,e,i)));i({})}))}_getProperties(e,t){this._session.post("Runtime.getProperties",{objectId:e,ownProperties:!0},((e,n)=>{t(e?[]:n.result)}))}_unrollArray(e,t,n,i){this._getProperties(e,(e=>{n[t]=e.filter((e=>"length"!==e.name&&!isNaN(parseInt(e.name,10)))).sort(((e,t)=>parseInt(e.name,10)-parseInt(t.name,10))).map((e=>(0,nn.z)([e,"optionalAccess",e=>e.value,"optionalAccess",e=>e.value]))),i(n)}))}_unrollObject(e,t,n,i){this._getProperties(e,(e=>{n[t]=e.map((e=>[e.name,(0,nn.z)([e,"optionalAccess",e=>e.value,"optionalAccess",e=>e.value])])).reduce(((e,[t,n])=>(e[t]=n,e)),{}),i(n)}))}_unrollOther(e,t,n){null!=(0,nn.z)([e,"optionalAccess",e=>e.value,"optionalAccess",e=>e.value])?t[e.name]=e.value.value:null!=(0,nn.z)([e,"optionalAccess",e=>e.value,"optionalAccess",e=>e.description])&&"function"!==(0,nn.z)([e,"optionalAccess",e=>e.value,"optionalAccess",e=>e.type])&&(t[e.name]=`<${e.value.description}>`),n(t)}}const ui="LocalVariables",bi=(0,l._C)(((e={},t=function(){try{return new di}catch(e){return}}())=>{const n=new Tn(20);let i,s=!1;function o(e){const t=li((0,nn.z)([e,"optionalAccess",e=>e.stacktrace,"optionalAccess",e=>e.frames]));if(void 0===t)return;const i=n.remove(t);if(void 0===i)return;const s=((0,nn.z)([e,"access",e=>e.stacktrace,"optionalAccess",e=>e.frames])||[]).filter((e=>"new Promise"!==e.function));for(let e=0;ee.getOptions,"call",e=>e()]);if(t&&(0,nn.z)([r,"optionalAccess",e=>e.includeLocalVariables])){if(pn.S.major<18)return void p.vF.log("The `LocalVariables` integration is only supported on Node >= v18.");const o=!1!==e.captureAllExceptions;if(t.configureAndConnect(((e,s)=>function(e,{params:{reason:s,data:o,callFrames:r}},a){if("exception"!==s&&"promiseRejection"!==s)return void a();(0,nn.z)([i,"optionalCall",e=>e()]);const c=function(e,t){if(void 0!==t)return li(e(t,1))}(e,(0,nn.z)([o,"optionalAccess",e=>e.description]));if(null==c)return void a();const{add:l,next:g}=gi((e=>{n.set(c,e),a()}));for(let e=0;e"local"===e.type)),a="global"!==s.className&&s.className?`${s.className}.${i}`:i;if(void 0===(0,nn.z)([o,"optionalAccess",e=>e.object,"access",e=>e.objectId]))l((t=>{t[e]={function:a},g(t)}));else{const n=o.object.objectId;l((i=>(0,nn.z)([t,"optionalAccess",e=>e.getLocalVariables,"call",t=>t(n,(t=>{i[e]={function:a,vars:t},g(i)}))])))}}g([])}(r.stackParser,e,s)),o),o){const n=e.maxExceptionsPerSecond||50;i=function(e,n,i){let s=0,o=5,r=0;return setInterval((()=>{var n;0===r?s>e&&(o*=2,n=o,p.vF.log(`Local variables rate-limit exceeded. Disabling capturing of caught exceptions for ${n} seconds.`),(0,nn.z)([t,"optionalAccess",e=>e.setPauseOnExceptions,"call",e=>e(!1)]),o>86400&&(o=86400),r=o):(r-=1,0===r&&(p.vF.log("Local variables rate-limit lifted."),(0,nn.z)([t,"optionalAccess",e=>e.setPauseOnExceptions,"call",e=>e(!0)]))),s=0}),1e3).unref(),()=>{s+=1}}(n)}s=!0}},processEvent:e=>s?function(e){for(const t of(0,nn.z)([e,"optionalAccess",e=>e.exception,"optionalAccess",e=>e.values])||[])o(t);return e}(e):e,_getCachedFramesCount:()=>n.size,_getFirstCachedFrame:()=>n.values()[0]}})),Ii=(0,l.F)(ui,bi),pi=bi;let Ci;const hi="Modules";function mi(){const e=n.c[n.s]&&n.c[n.s].paths||[],t=function(){try{return n.c?Object.keys(n.c):[]}catch(e){return[]}}(),i={},s={};return t.forEach((t=>{let n=t;const o=()=>{const t=n;if(n=(0,Sn.dirname)(t),!n||t===n||s[t])return;if(e.indexOf(n)<0)return o();const r=(0,Sn.join)(t,"package.json");if(s[t]=!0,!(0,Hn.existsSync)(r))return o();try{const e=JSON.parse((0,Hn.readFileSync)(r,"utf8"));i[e.name]=e.version}catch(e){}};o()})),i}const yi=(0,l._C)((()=>({name:hi,setupOnce(){},processEvent:e=>(e.modules={...e.modules,...(Ci||(Ci=mi()),Ci)},e)}))),Zi=(0,l.F)(hi,yi);function Gi(e){(0,p.pq)((()=>{console.error(e)}));const t=(0,c.KU)();void 0===t&&($n&&p.vF.warn("No NodeClient was defined, we are exiting the process now."),global.process.exit(1));const n=t.getOptions(),i=n&&n.shutdownTimeout&&n.shutdownTimeout>0&&n.shutdownTimeout||2e3;t.close(i).then((e=>{e||$n&&p.vF.warn("We reached the timeout for emptying the request buffer, still exiting now!"),global.process.exit(1)}),(e=>{$n&&p.vF.error(e)}))}const Bi="OnUncaughtException",Ai=(0,l._C)(((e={})=>{const t={exitEvenIfOtherHandlersAreRegistered:!0,...e};return{name:Bi,setupOnce(){},setup(e){global.process.on("uncaughtException",function(e,t){let n,i=!1,s=!1,o=!1;const r=e.getOptions();return Object.assign((a=>{let l=Gi;t.onFatalError?l=t.onFatalError:r.onFatalError&&(l=r.onFatalError);const g=0===global.process.listeners("uncaughtException").reduce(((e,t)=>"domainUncaughtExceptionClear"===t.name||t.tag&&"sentry_tracingErrorCallback"===t.tag||t._errorHandler?e:e+1),0),d=t.exitEvenIfOtherHandlersAreRegistered||g;i?d&&(o?($n&&p.vF.warn("uncaught exception after calling fatal error shutdown callback - this is bad! forcing shutdown"),Gi(a)):s||(s=!0,setTimeout((()=>{o||(o=!0,l(n,a))}),2e3))):(n=a,i=!0,(0,c.KU)()===e&&(0,c.Cp)(a,{originalException:a,captureContext:{level:"fatal"},mechanism:{handled:!1,type:"onuncaughtexception"}}),!o&&d&&(o=!0,l(a)))}),{_errorHandler:!0})}(e,t))}}})),Wi=(0,l.F)(Bi,Ai),fi="OnUnhandledRejection",Vi=(0,l._C)(((e={})=>{const t=e.mode||"warn";return{name:fi,setupOnce(){},setup(e){global.process.on("unhandledRejection",function(e,t){return function(n,i){(0,c.KU)()===e&&((0,c.Cp)(n,{originalException:i,captureContext:{extra:{unhandledPromiseRejection:!0}},mechanism:{handled:!1,type:"onunhandledrejection"}}),function(e,t){const n="This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:";"warn"===t.mode?(0,p.pq)((()=>{console.warn(n),console.error(e&&e.stack?e.stack:e)})):"strict"===t.mode&&((0,p.pq)((()=>{console.warn(n)})),Gi(e))}(n,t))}}(e,{mode:t}))}}})),vi=(0,l.F)(fi,Vi),Ri="Spotlight",Yi=(0,l._C)(((e={})=>{const t={sidecarUrl:e.sidecarUrl||"http://localhost:8969/stream"};return{name:Ri,setupOnce(){},setup(e){"object"==typeof process&&process.env&&p.vF.warn("[Spotlight] It seems you're not in dev mode. Do you really want to have Spotlight enabled?"),function(e,t){const n=function(e){try{return new en.URL(`${e}`)}catch(t){return void p.vF.warn(`[Spotlight] Invalid sidecar URL: ${e}`)}}(t.sidecarUrl);if(!n)return;let i=0;"function"==typeof e.on?e.on("beforeEnvelope",(e=>{if(i>3)return void p.vF.warn("[Spotlight] Disabled Sentry -> Spotlight integration due to too many failed requests");const t=M(e),s=function(){const{request:e}=Dt;return"__sentry_original__"in e?e.__sentry_original__:e}()({method:"POST",path:n.pathname,hostname:n.hostname,port:n.port,headers:{"Content-Type":"application/x-sentry-envelope"}},(e=>{e.on("data",(()=>{})),e.on("end",(()=>{})),e.setEncoding("utf8")}));s.on("error",(()=>{i++,p.vF.warn("[Spotlight] Failed to send envelope to Spotlight Sidecar")})),s.write(t),s.end()})):p.vF.warn("[Spotlight] Cannot connect to spotlight due to missing method on SDK client (`client.on`)")}(e,t)}}})),Xi=(0,l.F)(Ri,Yi);var Hi;!function(e){e.RequestCreate="undici:request:create",e.RequestEnd="undici:request:headers",e.RequestError="undici:request:error"}(Hi||(Hi={}));const Si=(0,l._C)((e=>new Ni(e)));class Ni{static __initStatic(){this.id="Undici"}__init(){this.name=Ni.id}__init2(){this._createSpanUrlMap=new Tn(100)}__init3(){this._headersUrlMap=new Tn(100)}constructor(e={}){Ni.prototype.__init.call(this),Ni.prototype.__init2.call(this),Ni.prototype.__init3.call(this),Ni.prototype.__init4.call(this),Ni.prototype.__init5.call(this),Ni.prototype.__init6.call(this),this._options={breadcrumbs:void 0===e.breadcrumbs||e.breadcrumbs,tracing:e.tracing,shouldCreateSpanForRequest:e.shouldCreateSpanForRequest}}setupOnce(e){if(pn.S.major<16)return;let t;try{t=n(1637)}catch(e){}t&&t.subscribe&&(t.subscribe(Hi.RequestCreate,this._onRequestCreate),t.subscribe(Hi.RequestEnd,this._onRequestEnd),t.subscribe(Hi.RequestError,this._onRequestError))}_shouldCreateSpan(e){if(!1===this._options.tracing||void 0===this._options.tracing&&!Ze())return!1;if(void 0===this._options.shouldCreateSpanForRequest)return!0;const t=this._createSpanUrlMap.get(e);if(void 0!==t)return t;const n=this._options.shouldCreateSpanForRequest(e);return this._createSpanUrlMap.set(e,n),n}__init4(){this._onRequestCreate=e=>{if(!(0,nn.z)([c.KU,"call",e=>e(),"optionalAccess",e=>e.getIntegration,"call",e=>e(Ni)]))return;const{request:t}=e,n=t.origin?t.origin.toString()+t.path:t.path,i=(0,c.KU)();if(!i)return;if(Mn(n,i)||void 0!==t.__sentry_span__)return;const s=i.getOptions(),o=(0,c.o5)(),r=(0,ne.rm)(),a=Ve(),l=this._shouldCreateSpan(n)?function(e,t,n){const i=function(e){if(!e)return{};const t=e.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)return{};const n=t[6]||"",i=t[8]||"";return{host:t[4],path:t[5],protocol:t[2],search:n,hash:i,relative:t[5]+n+i}}(n),s=t.method||"GET",o={"http.method":s};return i.search&&(o["http.query"]=i.search),i.hash&&(o["http.fragment"]=i.hash),(0,nn.z)([e,"optionalAccess",e=>e.startChild,"call",e=>e({op:"http.client",origin:"auto.http.node.undici",description:`${s} ${rt(i)}`,data:o})])}(a,t,n):void 0;if(l&&(t.__sentry_span__=l),(e=>{if(void 0===s.tracePropagationTargets)return!0;const t=this._headersUrlMap.get(e);if(void 0!==t)return t;const n=(0,h.Xr)(e,s.tracePropagationTargets);return this._headersUrlMap.set(e,n),n})(n)){const{traceId:e,spanId:n,sampled:s,dsc:a}={...r.getPropagationContext(),...o.getPropagationContext()};!function(e,t,n){let i;i=Array.isArray(e.headers)?e.headers.some((e=>"sentry-trace"===e)):e.headers.split("\r\n").some((e=>e.startsWith("sentry-trace:"))),i||(e.addHeader("sentry-trace",t),n&&e.addHeader("baggage",n))}(t,l?(0,me.Qh)(l):(0,he.TC)(e,n,s),(0,qn.De)(a||(l?(0,ge.k)(l):(0,ge.l)(e,i,o))))}}}__init5(){this._onRequestEnd=e=>{if(!(0,nn.z)([c.KU,"call",e=>e(),"optionalAccess",e=>e.getIntegration,"call",e=>e(Ni)]))return;const{request:t,response:n}=e,i=t.origin?t.origin.toString()+t.path:t.path;if(Mn(i,(0,c.KU)()))return;const s=t.__sentry_span__;s&&(Ue(s,n.statusCode),s.end()),this._options.breadcrumbs&&(0,c.ZQ)({category:"http",data:{method:t.method,status_code:n.statusCode,url:i},type:"http"},{event:"response",request:t,response:n})}}__init6(){this._onRequestError=e=>{if(!(0,nn.z)([c.KU,"call",e=>e(),"optionalAccess",e=>e.getIntegration,"call",e=>e(Ni)]))return;const{request:t}=e,n=t.origin?t.origin.toString()+t.path:t.path;if(Mn(n,(0,c.KU)()))return;const i=t.__sentry_span__;i&&(i.setStatus("internal_error"),i.end()),this._options.breadcrumbs&&(0,c.ZQ)({category:"http",data:{method:t.method,url:n},level:"error",type:"http"},{event:"error",request:t})}}}Ni.__initStatic();const wi=/^(\S+:\\|\/?)([\s\S]*?)((?:\.{1,2}|[^/\\]+?|)(\.[^./\\]*|))(?:[/\\]*)$/;function Ki(e){const t=e.length>1024?`${e.slice(-1024)}`:e,n=wi.exec(t);return n?n.slice(1):[]}function Fi(...e){let t="",n=!1;for(let i=e.length-1;i>=-1&&!n;i--){const s=i>=0?e[i]:"/";s&&(t=`${s}/${t}`,n="/"===s.charAt(0))}return t=function(e,t){let n=0;for(let t=e.length-1;t>=0;t--){const i=e[t];"."===i?e.splice(t,1):".."===i?(e.splice(t,1),n++):n&&(e.splice(t,1),n--)}if(t)for(;n--;n)e.unshift("..");return e}(t.split("/").filter((e=>!!e)),!n).join("/"),(n?"/":"")+t||"."}function ki(e){let t=0;for(;t=0&&""===e[n];n--);return t>n?[]:e.slice(t,n-t+1)}function _i(e){return e.replace(/^[A-Z]:/,"").replace(/\\/g,"/")}function Ji(e=(process.argv[1]?function(e){const t=Ki(process.argv[1]),n=t[0];let i=t[1];return n||i?(i&&(i=i.slice(0,i.length-1)),n+i):"."}():process.cwd()),t="\\"===Sn.sep){const n=t?_i(e):e;return e=>{if(!e)return;const i=t?_i(e):e;let{dir:s,base:o,ext:r}=Sn.posix.parse(i);".js"!==r&&".mjs"!==r&&".cjs"!==r||(o=o.slice(0,-1*r.length)),s||(s=".");const a=s.lastIndexOf("/node_modules");if(a>-1)return`${s.slice(a+14).replace(/\//g,".")}:${o}`;if(s.startsWith(n)){let e=s.slice(n.length+1).replace(/\//g,".");return e&&(e+=":"),e+=o,e}return o}}const zi=[B(),b(),w(),Ct(),Rn(),si(),Si(),Ai(),Vi(),Ln(),pi(),Fn(),yi()];function Ui(e){const t=(0,ne.EU)(),n=(0,nn.z)([t,"access",e=>e.__SENTRY__,"optionalAccess",e=>e.integrations])||[];return[...zi,...n]}function xi(e={}){Bn(),void 0===e.defaultIntegrations&&(e.defaultIntegrations=Ui()),void 0===e.dsn&&process.env.SENTRY_DSN&&(e.dsn=process.env.SENTRY_DSN);const t=process.env.SENTRY_TRACES_SAMPLE_RATE;if(void 0===e.tracesSampleRate&&t){const n=parseFloat(t);isFinite(n)&&(e.tracesSampleRate=n)}if(void 0===e.release){const t=Ei();void 0!==t?e.release=t:e.autoSessionTracking=!1}void 0===e.environment&&process.env.SENTRY_ENVIRONMENT&&(e.environment=process.env.SENTRY_ENVIRONMENT),void 0===e.autoSessionTracking&&void 0!==e.dsn&&(e.autoSessionTracking=!0),void 0===e.instrumenter&&(e.instrumenter="sentry");const n={...e,stackParser:(0,Xt.vk)(e.stackParser||Qi),integrations:(0,l.mH)(e),transport:e.transport||In};if(function(e,t){!0===t.debug&&(m.T?p.vF.enable():(0,p.pq)((()=>{console.warn("[Sentry] Cannot initialize SDK with `debug` option using a non-debug bundle.")}))),(0,c.o5)().update(t.initialScope);const n=new e(t);mt(n),function(e){e.init?e.init():e.setupIntegrations&&e.setupIntegrations()}(n)}(e.clientClass||Pt,n),e.autoSessionTracking&&((0,c.J0)(),process.on("beforeExit",(()=>{const e=(0,ne.rm)().getSession();e&&!["exited","crashed"].includes(e.status)&&(0,c.ky)()}))),function(){const e=(process.env.SENTRY_USE_ENVIRONMENT||"").toLowerCase();if(!["false","n","no","off","0"].includes(e)){const e=process.env.SENTRY_TRACE,t=process.env.SENTRY_BAGGAGE,n=(0,he.kM)(e,t);(0,c.o5)().setPropagationContext(n)}}(),e.spotlight){const t=(0,c.KU)();if(t&&t.addIntegration){const n=t.getOptions().integrations;for(const e of n)t.addIntegration(e);t.addIntegration(Yi({sidecarUrl:"string"==typeof e.spotlight?e.spotlight:void 0}))}}}function Ti(e){if(void 0===e)return!1;const t=e&&e.getOptions();return!(!t||void 0===t.autoSessionTracking)&&t.autoSessionTracking}function Ei(e){return process.env.SENTRY_RELEASE?process.env.SENTRY_RELEASE:Yt.OW.SENTRY_RELEASE&&Yt.OW.SENTRY_RELEASE.id?Yt.OW.SENTRY_RELEASE.id:process.env.GITHUB_SHA||process.env.COMMIT_REF||process.env.VERCEL_GIT_COMMIT_SHA||process.env.VERCEL_GITHUB_COMMIT_SHA||process.env.VERCEL_GITLAB_COMMIT_SHA||process.env.VERCEL_BITBUCKET_COMMIT_SHA||process.env.ZEIT_GITHUB_COMMIT_SHA||process.env.ZEIT_GITLAB_COMMIT_SHA||process.env.ZEIT_BITBUCKET_COMMIT_SHA||process.env.CF_PAGES_COMMIT_SHA||e}const Qi=(0,Xt.gd)((0,Xt.o)(Ji()));function Li(e){const t=Sn.resolve(e);if(!Hn.existsSync(t))throw new Error(`Cannot read contents of ${t}. Directory does not exist.`);if(!Hn.statSync(t).isDirectory())throw new Error(`Cannot read contents of ${t}, because it is not a directory.`);const n=e=>Hn.readdirSync(e).reduce(((t,i)=>{const s=Sn.join(e,i);return Hn.statSync(s).isDirectory()?t.concat(n(s)):(t.push(s),t)}),[]);return n(t).map((e=>Sn.relative(t,e)))}var ji=n(1615);function Oi(e){const t=(0,c.KU)();return new ji.M(e).setup(t),Promise.resolve()}function Pi(e={}){return function({path:t,type:n,next:i,rawInput:s}){const o=(0,nn.z)([c.KU,"call",e=>e(),"optionalAccess",e=>e.getOptions,"call",e=>e()]),r=(0,c.o5)().getTransaction();if(r){r.updateName(`trpc/${t}`),r.setAttribute(k,"route"),r.op="rpc.server";const i={procedure_type:n};(void 0!==e.attachRpcInput?e.attachRpcInput:(0,nn.z)([o,"optionalAccess",e=>e.sendDefaultPii]))&&(i.input=(0,X.S8)(s)),r.setContext("trpc",i)}function a(e){e.ok||(0,c.Cp)(e.error,{mechanism:{handled:!1,data:{function:"trpcMiddleware"}}})}let l;try{l=i()}catch(e){throw(0,c.Cp)(e,{mechanism:{handled:!1,data:{function:"trpcMiddleware"}}}),e}return(0,f.Qg)(l)?Promise.resolve(l).then((e=>{a(e)}),(e=>{(0,c.Cp)(e,{mechanism:{handled:!1,data:{function:"trpcMiddleware"}}})})):a(l),l}}function Mi(e,t){return dt(e,{include:t})}function Di(e,t,n={}){return ut(e,t,{include:n})}function qi(){return function(e,t,n){const i=(0,nn.z)([c.KU,"call",e=>e(),"optionalAccess",e=>e.getOptions,"call",e=>e()]);if(!i||"sentry"!==i.instrumenter||"OPTIONS"===(0,nn.z)([e,"access",e=>e.method,"optionalAccess",e=>e.toUpperCase,"call",e=>e()])||"HEAD"===(0,nn.z)([e,"access",e=>e.method,"optionalAccess",e=>e.toUpperCase,"call",e=>e()]))return n();const s=e.headers&&(0,f.Kg)(e.headers["sentry-trace"])?e.headers["sentry-trace"]:void 0,o=(0,nn.z)([e,"access",e=>e.headers,"optionalAccess",e=>e.baggage]);if(!Ze(i))return n();const[r,a]=gt(e,{path:!0,method:!0}),l=ve({sentryTrace:s,baggage:o},(t=>(0,c.nb)({name:r,op:"http.server",origin:"auto.http.node.tracingHandler",...t,data:{[k]:a},metadata:{...t.metadata,request:e}},{request:dt(e)})));(0,c.o5)().setSpan(l),t.__sentry_transaction=l,t.once("finish",(()=>{setImmediate((()=>{!function(e,t,n){if(e){if(!e.metadata.source||"url"===e.metadata.source){const[n,i]=gt(t,{path:!0,method:!0});e.updateName(n),e.setMetadata({source:i})}e.setAttribute("url",t.originalUrl||t.url),t.baseUrl&&e.setAttribute("baseUrl",t.baseUrl),e.setData("query",bt(t,void 0))}}(l,e),Ue(l,t.statusCode),l.end()}))})),n()}}function $i(e){const t=function(e={}){let t;if("include"in e)t={include:e.include};else{const{ip:n,request:i,transaction:s,user:o}=e;(n||i||s||o)&&(t={include:(0,a.Ce)({ip:n,request:i,transaction:s,user:o})})}return t}(e),n=(0,c.KU)();if(n&&Ti(n)){n.initSessionFlusher();const e=(0,c.o5)();e.getSession()&&e.setSession()}return function(n,i,s){if(e&&e.flushTimeout&&e.flushTimeout>0){const t=i.end;i.end=function(n,i,s){(0,c.bX)(e.flushTimeout).then((()=>{t.call(this,n,i,s)})).then(null,(e=>{$n&&p.vF.error(e),t.call(this,n,i,s)}))}}(0,ne.fx)((()=>{const e=(0,c.o5)();e.setSDKProcessingMetadata({request:n,requestDataOptionsFromExpressHandler:t}),Ti((0,c.KU)())&&e.setRequestSession({status:"ok"}),i.once("finish",(()=>{const e=(0,c.KU)();Ti(e)&&setImmediate((()=>{e&&e._captureRequestSession&&e._captureRequestSession()}))})),s()}))}}function es(e){const t=function(e){const t=e.status||e.statusCode||e.status_code||e.output&&e.output.statusCode;return t?parseInt(t,10):500}(e);return t>=500}function ts(e){return function(t,n,i,s){(e&&e.shouldHandleError||es)(t)?(0,c.v4)((e=>{e.setSDKProcessingMetadata({request:n});const o=i.__sentry_transaction;o&&!Ve()&&e.setSpan(o);const r=(0,c.KU)();if(r&&Ti(r)&&void 0!==r._sessionFlusher){const t=e.getRequestSession();t&&void 0!==t.status&&(t.status="crashed")}const a=(0,c.Cp)(t,{mechanism:{type:"middleware",handled:!1}});i.sentry=a,s(t)})):s(t)}}const ns=Pi;function is(e){return e&&void 0!==e.statusCode}const ss={name:"SentryHapiErrorPlugin",version:Zt.M,register:async function(e){e.events.on("request",((e,t)=>{const n=Fe();var i;(function(e){return e&&void 0!==e.error})(t)&&(i=t.error,(0,c.Cp)(i,{mechanism:{type:"hapi",handled:!1,data:{function:"hapiErrorPlugin"}}})),n&&(n.setStatus("internal_error"),n.end())}))}},os={name:"SentryHapiTracingPlugin",version:Zt.M,register:async function(e){const t=e;t.ext("onPreHandler",((e,t)=>{const n=ve({sentryTrace:e.headers["sentry-trace"]||void 0,baggage:e.headers.baggage||void 0},(t=>(0,c.nb)({...t,op:"hapi.request",name:e.route.path,description:`${e.route.method} ${e.path}`})));return(0,c.o5)().setSpan(n),t.continue})),t.ext("onPreResponse",((e,t)=>{const n=Fe();if(e.response&&is(e.response)&&n){const t=e.response;t.header("sentry-trace",(0,me.Qh)(n));const i=(0,qn.De)((0,ge.k)(n));i&&t.header("baggage",i)}return t.continue})),t.ext("onPostHandler",((e,t)=>{const n=Fe();return n&&(e.response&&is(e.response)&&Ue(n,e.response.statusCode),n.end()),t.continue}))}},rs="Hapi",as=(0,l._C)(((e={})=>{const t=e.server;return{name:rs,setupOnce(){t&&(0,a.GS)(t,"start",(e=>async function(){return await this.register(os),await this.register(ss),e.apply(this)}))}}})),cs=(0,l.F)(rs,as);var ls=n(3903);const gs="undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__;function ds(e){const t=(0,nn.z)([e,"call",e=>e(),"access",e=>e.getClient,"call",e=>e(),"optionalAccess",e=>e.getOptions,"call",e=>e()]);return"sentry"!==((0,nn.z)([t,"optionalAccess",e=>e.instrumenter])||"sentry")}class us{static __initStatic(){this.id="Apollo"}constructor(e={useNestjs:!1}){this.name=us.id,this._useNest=!!e.useNestjs}loadDependency(){return this._useNest?this._module=this._module||(0,ls.Vw)("@nestjs/graphql"):this._module=this._module||(0,ls.Vw)("apollo-server-core"),this._module}setupOnce(e,t){if(ds(t))gs&&p.vF.log("Apollo Integration is skipped because of instrumenter configuration.");else if(this._useNest){const e=this.loadDependency();if(!e)return void(gs&&p.vF.error("Apollo-NestJS Integration was unable to require @nestjs/graphql package."));(0,a.GS)(e.GraphQLFactory.prototype,"mergeWithSchema",(function(e){return function(...n){return(0,a.GS)(this.resolversExplorerService,"explore",(function(e){return function(){return bs((0,C.k9)(e.call(this)),t)}})),e.call(this,...n)}}))}else{const e=this.loadDependency();if(!e)return void(gs&&p.vF.error("Apollo Integration was unable to require apollo-server-core package."));(0,a.GS)(e.ApolloServerBase.prototype,"constructSchema",(function(e){return function(){if(!this.config.resolvers)return gs&&(this.config.schema?(p.vF.warn("Apollo integration is not able to trace `ApolloServer` instances constructed via `schema` property.If you are using NestJS with Apollo, please use `Sentry.Integrations.Apollo({ useNestjs: true })` instead."),p.vF.warn()):this.config.modules&&p.vF.warn("Apollo integration is not able to trace `ApolloServer` instances constructed via `modules` property."),p.vF.error("Skipping tracing as no resolvers found on the `ApolloServer` instance.")),e.call(this);const n=(0,C.k9)(this.config.resolvers);return this.config.resolvers=bs(n,t),e.call(this)}}))}}}function bs(e,t){return e.map((e=>(Object.keys(e).forEach((n=>{Object.keys(e[n]).forEach((i=>{"function"==typeof e[n][i]&&function(e,t,n,i){(0,a.GS)(e[t],n,(function(e){return function(...s){const o=i().getScope().getSpan(),r=(0,nn.z)([o,"optionalAccess",e=>e.startChild,"call",e=>e({description:`${t}.${n}`,op:"graphql.resolve",origin:"auto.graphql.apollo"})]),a=e.call(this,...s);return(0,f.Qg)(a)?a.then((e=>((0,nn.z)([r,"optionalAccess",e=>e.end,"call",e=>e()]),e))):((0,nn.z)([r,"optionalAccess",e=>e.end,"call",e=>e()]),a)}}))}(e,n,i,t)}))})),e)))}us.__initStatic();class Is{static __initStatic(){this.id="Express"}constructor(e={}){this.name=Is.id,this._router=e.router||e.app,this._methods=(Array.isArray(e.methods)?e.methods:[]).concat("use")}setupOnce(e,t){this._router?ds(t)?gs&&p.vF.log("Express Integration is skipped because of instrumenter configuration."):(function(e,t=[]){t.forEach((t=>function(e,t){const n=e[t];return e[t]=function(...e){return n.call(this,...function(e,t){return e.map((e=>"function"==typeof e?ps(e,t):Array.isArray(e)?e.map((e=>"function"==typeof e?ps(e,t):e)):e))}(e,t))},e}(e,t)))}(this._router,this._methods),function(e){const t="settings"in e;t&&void 0===e._router&&e.lazyrouter&&e.lazyrouter();const n=t?e._router:e;if(!n)return gs&&p.vF.debug("Cannot instrument router for URL Parameterization (did not find a valid router)."),void(gs&&p.vF.debug("Routing instrumentation is currently only supported in Express 4."));const i=Object.getPrototypeOf(n),s=i.process_params;i.process_params=function(e,t,n,i,o){n._reconstructedRoute||(n._reconstructedRoute="");const{layerRoutePath:r,isRegex:a,isArray:c,numExtraSegments:l}=function(e){let t=(0,nn.z)([e,"access",e=>e.route,"optionalAccess",e=>e.path]);const n=(0,f.gd)(t),i=Array.isArray(t);if(!t){const[n]=Yt.OW.process.versions.node.split(".").map(Number);n>=16&&(t=Cs(e.path,e.regexp,e.keys))}if(!t)return{isRegex:n,isArray:i,numExtraSegments:0};const s=i?Math.max(t.reduce(((e,t)=>e+ot(t.toString())),0)-ot(e.path||""),0):0,o=function(e,t){return e?t.map((e=>e.toString())).join(","):t&&t.toString()}(i,t);return{layerRoutePath:o,isRegex:n,isArray:i,numExtraSegments:s}}(e);let g;(r||a||c)&&(n._hasParameters=!0),g=r||function(e,t,n){const i=st(e||""),s=(0,nn.z)([i,"optionalAccess",e=>e.split,"call",e=>e("/"),"access",e=>e.filter,"call",e=>e((e=>!!e))]);let o=0;const r=(0,nn.z)([t,"optionalAccess",e=>e.split,"call",e=>e("/"),"access",e=>e.filter,"call",e=>e((e=>!!e)),"access",e=>e.length])||0;return(0,nn.z)([n,"optionalAccess",e=>e.split,"call",e=>e("/"),"access",e=>e.filter,"call",e=>e((e=>(0,nn.z)([s,"optionalAccess",e=>e[r+o]])===e&&(o+=1,!0))),"access",e=>e.join,"call",e=>e("/")])}(n.originalUrl,n._reconstructedRoute,e.path)||"";const d=g.split("/").filter((e=>e.length>0&&(a||c||!e.includes("*")))).join("/");if(d&&d.length>0&&(n._reconstructedRoute+=`/${d}${a?"/":""}`),ot(st(n.originalUrl||""))+l===ot(n._reconstructedRoute)){n._hasParameters||n._reconstructedRoute!==n.originalUrl&&(n._reconstructedRoute=n.originalUrl?st(n.originalUrl):n.originalUrl);const e=i.__sentry_transaction,t=e&&(0,me.et)(e).data||{};if(e&&"custom"!==t[k]){const t=n._reconstructedRoute||"/",[i,s]=gt(n,{path:!0,method:!0,customRoute:t});e.updateName(i),e.setAttribute(k,s)}}return s.call(this,e,t,n,i,o)}}(this._router)):gs&&p.vF.error("ExpressIntegration is missing an Express instance")}}function ps(e,t){const n=e.length;switch(n){case 2:return function(n,i){const s=i.__sentry_transaction;if(s){const n=s.startChild({description:e.name,op:`middleware.express.${t}`,origin:"auto.middleware.express"});i.once("finish",(()=>{n.end()}))}return e.call(this,n,i)};case 3:return function(n,i,s){const o=i.__sentry_transaction,r=(0,nn.z)([o,"optionalAccess",e=>e.startChild,"call",n=>n({description:e.name,op:`middleware.express.${t}`,origin:"auto.middleware.express"})]);e.call(this,n,i,(function(...e){(0,nn.z)([r,"optionalAccess",e=>e.end,"call",e=>e()]),s.call(this,...e)}))};case 4:return function(n,i,s,o){const r=s.__sentry_transaction,a=(0,nn.z)([r,"optionalAccess",e=>e.startChild,"call",n=>n({description:e.name,op:`middleware.express.${t}`,origin:"auto.middleware.express"})]);e.call(this,n,i,s,(function(...e){(0,nn.z)([a,"optionalAccess",e=>e.end,"call",e=>e()]),o.call(this,...e)}))};default:throw new Error(`Express middleware takes 2-4 arguments. Got: ${n}`)}}Is.__initStatic();const Cs=(e,t,n)=>{if(!(e&&t&&n&&0!==Object.keys(n).length&&(0,nn.z)([n,"access",e=>e[0],"optionalAccess",e=>e.offset])))return;const i=n.sort(((e,t)=>e.offset-t.offset)),s=new RegExp(t,`${t.flags}d`).exec(e);if(!s||!s.indices)return;const[,...o]=s.indices;if(o.length!==i.length)return;let r=e,a=0;return o.forEach(((e,t)=>{if(e){const[n,s]=e,o=r.substring(0,n-a),c=`:${i[t].name}`,l=r.substring(s-a);r=o+c+l,a+=s-n-c.length}})),r};class hs{static __initStatic(){this.id="GraphQL"}constructor(){this.name=hs.id}loadDependency(){return this._module=this._module||(0,ls.Vw)("graphql/execution/execute.js")}setupOnce(e,t){if(ds(t))return void(gs&&p.vF.log("GraphQL Integration is skipped because of instrumenter configuration."));const n=this.loadDependency();n?(0,a.GS)(n,"execute",(function(e){return function(...n){const i=t().getScope(),s=i.getSpan(),o=(0,nn.z)([s,"optionalAccess",e=>e.startChild,"call",e=>e({description:"execute",op:"graphql.execute",origin:"auto.graphql.graphql"})]);(0,nn.z)([i,"optionalAccess",e=>e.setSpan,"call",e=>e(o)]);const r=e.call(this,...n);return(0,f.Qg)(r)?r.then((e=>((0,nn.z)([o,"optionalAccess",e=>e.end,"call",e=>e()]),(0,nn.z)([i,"optionalAccess",e=>e.setSpan,"call",e=>e(s)]),e))):((0,nn.z)([o,"optionalAccess",e=>e.end,"call",e=>e()]),(0,nn.z)([i,"optionalAccess",e=>e.setSpan,"call",e=>e(s)]),r)}})):gs&&p.vF.error("GraphQL Integration was unable to require graphql/execution package.")}}hs.__initStatic();const ms=["aggregate","bulkWrite","countDocuments","createIndex","createIndexes","deleteMany","deleteOne","distinct","drop","dropIndex","dropIndexes","estimatedDocumentCount","find","findOne","findOneAndDelete","findOneAndReplace","findOneAndUpdate","indexes","indexExists","indexInformation","initializeOrderedBulkOp","insertMany","insertOne","isCapped","mapReduce","options","parallelCollectionScan","rename","replaceOne","stats","updateMany","updateOne"],ys={bulkWrite:["operations"],countDocuments:["query"],createIndex:["fieldOrSpec"],createIndexes:["indexSpecs"],deleteMany:["filter"],deleteOne:["filter"],distinct:["key","query"],dropIndex:["indexName"],find:["query"],findOne:["query"],findOneAndDelete:["filter"],findOneAndReplace:["filter","replacement"],findOneAndUpdate:["filter","update"],indexExists:["indexes"],insertMany:["docs"],insertOne:["doc"],mapReduce:["map","reduce"],rename:["newName"],replaceOne:["filter","doc"],updateMany:["filter","update"],updateOne:["filter","update"]};class Zs{static __initStatic(){this.id="Mongo"}constructor(e={}){this.name=Zs.id,this._operations=Array.isArray(e.operations)?e.operations:ms,this._describeOperations=!("describeOperations"in e)||e.describeOperations,this._useMongoose=!!e.useMongoose}loadDependency(){const e=this._useMongoose?"mongoose":"mongodb";return this._module=this._module||(0,ls.Vw)(e)}setupOnce(e,t){if(ds(t))return void(gs&&p.vF.log("Mongo Integration is skipped because of instrumenter configuration."));const n=this.loadDependency();if(n)this._instrumentOperations(n.Collection,this._operations,t);else{const e=this._useMongoose?"mongoose":"mongodb";gs&&p.vF.error(`Mongo Integration was unable to require \`${e}\` package.`)}}_instrumentOperations(e,t,n){t.forEach((t=>this._patchOperation(e,t,n)))}_patchOperation(e,t,n){if(!(t in e.prototype))return;const i=this._getSpanContextFromOperationArguments.bind(this);(0,a.GS)(e.prototype,t,(function(e){return function(...s){const o=s[s.length-1],r=n(),a=r.getScope(),c=r.getClient(),l=a.getSpan(),g=(0,nn.z)([c,"optionalAccess",e=>e.getOptions,"call",e=>e(),"access",e=>e.sendDefaultPii]);if("function"!=typeof o||"mapReduce"===t&&2===s.length){const n=(0,nn.z)([l,"optionalAccess",e=>e.startChild,"call",e=>e(i(this,t,s,g))]),o=e.call(this,...s);if((0,f.Qg)(o))return o.then((e=>((0,nn.z)([n,"optionalAccess",e=>e.end,"call",e=>e()]),e)));if((d=o)&&"object"==typeof d&&d.once&&"function"==typeof d.once){const e=o;try{e.once("close",(()=>{(0,nn.z)([n,"optionalAccess",e=>e.end,"call",e=>e()])}))}catch(e){(0,nn.z)([n,"optionalAccess",e=>e.end,"call",e=>e()])}return e}return(0,nn.z)([n,"optionalAccess",e=>e.end,"call",e=>e()]),o}var d;const u=(0,nn.z)([l,"optionalAccess",e=>e.startChild,"call",e=>e(i(this,t,s.slice(0,-1)))]);return e.call(this,...s.slice(0,-1),(function(e,t){(0,nn.z)([u,"optionalAccess",e=>e.end,"call",e=>e()]),o(e,t)}))}}))}_getSpanContextFromOperationArguments(e,t,n,i=!1){const s={"db.system":"mongodb","db.name":e.dbName,"db.operation":t,"db.mongodb.collection":e.collectionName},o={op:"db",origin:"auto.db.mongo",description:t,data:s},r=ys[t],a=Array.isArray(this._describeOperations)?this._describeOperations.includes(t):this._describeOperations;if(!r||!a||!i)return o;try{if("mapReduce"===t){const[e,t]=n;s[r[0]]="string"==typeof e?e:e.name||"",s[r[1]]="string"==typeof t?t:t.name||""}else for(let e=0;e(i||(i=t.config),e.apply(t,n))})}catch(e){gs&&p.vF.error("Mysql Integration was unable to instrument `mysql` config.")}function s(e){if(!e)return;const t=i?{"server.address":i.host,"server.port":i.port,"db.user":i.user}:{};Object.keys(t).forEach((n=>{e.setAttribute(n,t[n])})),e.end()}(0,a.GS)(n,"createQuery",(function(e){return function(n,i,o){const r=t().getScope().getSpan(),a=(0,nn.z)([r,"optionalAccess",e=>e.startChild,"call",e=>e({description:"string"==typeof n?n:n.sql,op:"db",origin:"auto.db.mysql",data:{"db.system":"mysql"}})]);if("function"==typeof o)return e.call(this,n,i,(function(e,t,n){s(a),o(e,t,n)}));if("function"==typeof i)return e.call(this,n,(function(e,t,n){s(a),i(e,t,n)}));const c=e.call(this,n,i);return c.on("end",(()=>{s(a)})),c}}))}}Gs.__initStatic();class Bs{static __initStatic(){this.id="Postgres"}constructor(e={}){this.name=Bs.id,this._usePgNative=!!e.usePgNative,this._module=e.module}loadDependency(){return this._module=this._module||(0,ls.Vw)("pg")}setupOnce(e,t){if(ds(t))return void(gs&&p.vF.log("Postgres Integration is skipped because of instrumenter configuration."));const n=this.loadDependency();if(!n)return void(gs&&p.vF.error("Postgres Integration was unable to require `pg` package."));const i=this._usePgNative?(0,nn.z)([n,"access",e=>e.native,"optionalAccess",e=>e.Client]):n.Client;i?(0,a.GS)(i.prototype,"query",(function(e){return function(n,i,s){const o=t().getScope().getSpan(),r={"db.system":"postgresql"};try{this.database&&(r["db.name"]=this.database),this.host&&(r["server.address"]=this.host),this.port&&(r["server.port"]=this.port),this.user&&(r["db.user"]=this.user)}catch(e){}const a=(0,nn.z)([o,"optionalAccess",e=>e.startChild,"call",e=>e({description:"string"==typeof n?n:n.text,op:"db",origin:"auto.db.postgres",data:r})]);if("function"==typeof s)return e.call(this,n,i,(function(e,t){(0,nn.z)([a,"optionalAccess",e=>e.end,"call",e=>e()]),s(e,t)}));if("function"==typeof i)return e.call(this,n,(function(e,t){(0,nn.z)([a,"optionalAccess",e=>e.end,"call",e=>e()]),i(e,t)}));const c=void 0!==i?e.call(this,n,i):e.call(this,n);return(0,f.Qg)(c)?c.then((e=>((0,nn.z)([a,"optionalAccess",e=>e.end,"call",e=>e()]),e))):((0,nn.z)([a,"optionalAccess",e=>e.end,"call",e=>e()]),c)}})):gs&&p.vF.error("Postgres Integration was unable to access 'pg-native' bindings.")}}Bs.__initStatic();class As{static __initStatic(){this.id="Prisma"}constructor(e={}){if(this.name=As.id,(t=e.client)&&t.$use&&!e.client._sentryInstrumented){(0,a.my)(e.client,"_sentryInstrumented",!0);const t={};try{const n=e.client._engineConfig;if(n){const{activeProvider:e,clientVersion:i}=n;e&&(t["db.system"]=e),i&&(t["db.prisma.version"]=i)}}catch(e){}e.client.$use(((e,n)=>{if(ds(ne.BF))return n(e);const i=e.action,s=e.model;return Be({name:s?`${s} ${i}`:i,onlyIfParent:!0,op:"db.prisma",attributes:{[z]:"auto.db.prisma"},data:{...t,"db.operation":i}},(()=>n(e)))}))}else gs&&p.vF.warn("Unsupported Prisma client provided to PrismaIntegration. Provided client:",e.client);var t}setupOnce(){}}As.__initStatic();const Ws="CaptureConsole",fs=(0,l._C)(((e={})=>{const t=e.levels||p.Ow;return{name:Ws,setupOnce(){},setup(e){"console"in Yt.OW&&An((({args:n,level:i})=>{(0,c.KU)()===e&&t.includes(i)&&function(e,t){const n={level:Vn(t),extra:{arguments:e}};(0,c.v4)((i=>{if(i.addEventProcessor((e=>(e.logger="console",(0,C.M6)(e,{handled:!1,type:"console"}),e))),"assert"===t&&!1===e[0]){const t=`Assertion failed: ${(0,h.gt)(e.slice(1)," ")||"console.assert"}`;return i.setExtra("arguments",e.slice(1)),void(0,c.wd)(t,n)}const s=e.find((e=>e instanceof Error));if("error"===t&&s)return void(0,c.Cp)(s,n);const o=(0,h.gt)(e," ");(0,c.wd)(o,n)}))}(n,i)}))}}}));(0,l.F)(Ws,fs);const Vs="Debug",vs=(0,l._C)(((e={})=>{const t={debugger:!1,stringify:!1,...e};return{name:Vs,setupOnce(){},setup(e){e.on&&e.on("beforeSendEvent",((e,n)=>{t.debugger,(0,p.pq)((()=>{t.stringify?(console.log(JSON.stringify(e,null,2)),n&&Object.keys(n).length&&console.log(JSON.stringify(n,null,2))):(console.log(e),n&&Object.keys(n).length&&console.log(n))}))}))}}})),Rs=((0,l.F)(Vs,vs),"undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__),Ys="Dedupe",Xs=(0,l._C)((()=>{let e;return{name:Ys,setupOnce(){},processEvent(t){if(t.type)return t;try{if(function(e,t){return!!t&&(!!function(e,t){const n=e.message,i=t.message;return!(!n&&!i)&&(!(n&&!i||!n&&i)&&(n===i&&(!!Ss(e,t)&&!!Hs(e,t))))}(e,t)||!!function(e,t){const n=Ns(t),i=Ns(e);return!(!n||!i)&&(n.type===i.type&&n.value===i.value&&(!!Ss(e,t)&&!!Hs(e,t)))}(e,t))}(t,e))return Rs&&p.vF.warn("Event dropped due to being a duplicate of previously captured event."),null}catch(e){}return e=t}}}));function Hs(e,t){let n=ws(e),i=ws(t);if(!n&&!i)return!0;if(n&&!i||!n&&i)return!1;if(i.length!==n.length)return!1;for(let e=0;e{const t=e.depth||3,n=e.captureErrorCause||!1;return{name:Ks,setupOnce(){},processEvent:(e,i)=>function(e,t={},n,i){if(!t.originalException||!(0,f.bJ)(t.originalException))return e;const s=t.originalException.name||t.originalException.constructor.name,o=function(e,t){try{const n=["name","message","stack","line","column","fileName","lineNumber","columnNumber","toJSON"],i={};for(const t of Object.keys(e)){if(-1!==n.indexOf(t))continue;const s=e[t];i[t]=(0,f.bJ)(s)?s.toString():s}if(t&&void 0!==e.cause&&(i.cause=(0,f.bJ)(e.cause)?e.cause.toString():e.cause),"function"==typeof e.toJSON){const t=e.toJSON();for(const e of Object.keys(t)){const n=t[e];i[e]=(0,f.bJ)(n)?n.toString():n}}return i}catch(e){Rs&&p.vF.error("Unable to extract extra data from the Error object:",e)}return null}(t.originalException,i);if(o){const t={...e.contexts},i=(0,X.S8)(o,n);return(0,f.Qd)(i)&&((0,a.my)(i,"__sentry_skip_normalization__",!0),t[s]=i),{...e,contexts:t}}return e}(e,i,t,n)}}));(0,l.F)(Ks,Fs);const ks=(0,Yt.VZ)();function _s(e){return e&&/^function fetch\(\)\s+\{\s+\[native code\]\s+\}$/.test(e.toString())}function Js(){if("string"==typeof EdgeRuntime)return!0;if(!function(){if(!("fetch"in ks))return!1;try{return new Headers,new Request("http://www.example.com"),new Response,!0}catch(e){return!1}}())return!1;if(_s(ks.fetch))return!0;let e=!1;const t=ks.document;if(t&&"function"==typeof t.createElement)try{const n=t.createElement("iframe");n.hidden=!0,t.head.appendChild(n),n.contentWindow&&n.contentWindow.fetch&&(e=_s(n.contentWindow.fetch)),t.head.removeChild(n)}catch(e){U.T&&p.vF.warn("Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ",e)}return e}function zs(){Js()&&(0,a.GS)(Yt.OW,"fetch",(function(e){return function(...t){const{method:n,url:i}=function(e){if(0===e.length)return{method:"GET",url:""};if(2===e.length){const[t,n]=e;return{url:xs(t),method:Us(n,"method")?String(n.method).toUpperCase():"GET"}}const t=e[0];return{url:xs(t),method:Us(t,"method")?String(t.method).toUpperCase():"GET"}}(t),s={args:t,fetchData:{method:n,url:i},startTimestamp:Date.now()};return Kt("fetch",{...s}),e.apply(Yt.OW,t).then((e=>(Kt("fetch",{...s,endTimestamp:Date.now(),response:e}),e)),(e=>{throw Kt("fetch",{...s,endTimestamp:Date.now(),error:e}),e}))}}))}function Us(e,t){return!!e&&"object"==typeof e&&!!e[t]}function xs(e){return"string"==typeof e?e:e?Us(e,"url")?e.url:e.toString?e.toString():"":""}const Ts=Yt.OW,Es="__sentry_xhr_v3__";function Qs(){if(!Ts.XMLHttpRequest)return;const e=XMLHttpRequest.prototype;(0,a.GS)(e,"open",(function(e){return function(...t){const n=Date.now(),i=(0,f.Kg)(t[0])?t[0].toUpperCase():void 0,s=function(e){if((0,f.Kg)(e))return e;try{return e.toString()}catch(e){}}(t[1]);if(!i||!s)return e.apply(this,t);this[Es]={method:i,url:s,request_headers:{}},"POST"===i&&s.match(/sentry_key/)&&(this.__sentry_own_request__=!0);const o=()=>{const e=this[Es];if(e&&4===this.readyState){try{e.status_code=this.status}catch(e){}Kt("xhr",{args:[i,s],endTimestamp:Date.now(),startTimestamp:n,xhr:this})}};return"onreadystatechange"in this&&"function"==typeof this.onreadystatechange?(0,a.GS)(this,"onreadystatechange",(function(e){return function(...t){return o(),e.apply(this,t)}})):this.addEventListener("readystatechange",o),(0,a.GS)(this,"setRequestHeader",(function(e){return function(...t){const[n,i]=t,s=this[Es];return s&&(0,f.Kg)(n)&&(0,f.Kg)(i)&&(s.request_headers[n.toLowerCase()]=i),e.apply(this,t)}})),e.apply(this,t)}})),(0,a.GS)(e,"send",(function(e){return function(...t){const n=this[Es];return n?(void 0!==t[0]&&(n.body=t[0]),Kt("xhr",{args:[n.method,n.url],startTimestamp:Date.now(),xhr:this}),e.apply(this,t)):e.apply(this,t)}}))}const Ls="HttpClient",js=(0,l._C)(((e={})=>{const t={failedRequestStatusCodes:[[500,599]],failedRequestTargets:[/.*/],...e};return{name:Ls,setupOnce(){},setup(e){!function(e,t){Js()&&function(n){const i="fetch";Nt(i,(n=>{if((0,c.KU)()!==e)return;const{response:i,args:s}=n,[o,r]=s;i&&function(e,t,n,i){if(Ms(e,n.status,n.url)){const e=function(e,t){return!t&&e instanceof Request||e instanceof Request&&e.bodyUsed?e:new Request(e,t)}(t,i);let s,o,r,a;qs()&&([{headers:s,cookies:r},{headers:o,cookies:a}]=[{cookieHeader:"Cookie",obj:e},{cookieHeader:"Set-Cookie",obj:n}].map((({cookieHeader:e,obj:t})=>{const n=function(e){const t={};return e.forEach(((e,n)=>{t[n]=e})),t}(t.headers);let i;try{const t=n[e]||n[e.toLowerCase()]||void 0;t&&(i=Ps(t))}catch(t){Rs&&p.vF.log(`Could not extract cookies from header ${e}`)}return{headers:n,cookies:i}})));const l=Ds({url:e.url,method:e.method,status:n.status,requestHeaders:s,responseHeaders:o,requestCookies:r,responseCookies:a});(0,c.r)(l)}}(t,o,i,r)})),wt(i,zs)}()}(e,t),function(e,t){var n;"XMLHttpRequest"in Yt.OW&&(n=n=>{if((0,c.KU)()!==e)return;const i=n.xhr,s=i[Es];if(!s)return;const{method:o,request_headers:r}=s;try{!function(e,t,n,i){if(Ms(e,t.status,t.responseURL)){let e,s,o;if(qs()){try{const e=t.getResponseHeader("Set-Cookie")||t.getResponseHeader("set-cookie")||void 0;e&&(s=Ps(e))}catch(e){Rs&&p.vF.log("Could not extract cookies from response headers")}try{o=function(e){const t=e.getAllResponseHeaders();return t?t.split("\r\n").reduce(((e,t)=>{const[n,i]=t.split(": ");return e[n]=i,e}),{}):{}}(t)}catch(e){Rs&&p.vF.log("Could not extract headers from response")}e=i}const r=Ds({url:t.responseURL,method:n,status:t.status,requestHeaders:e,responseHeaders:o,responseCookies:s});(0,c.r)(r)}}(t,i,o,r)}catch(e){Rs&&p.vF.warn("Error while extracting response event form XHR response",e)}},Nt("xhr",n),wt("xhr",Qs))}(e,t)}}}));function Os(e){if(e){const t=e["Content-Length"]||e["content-length"];if(t)return parseInt(t,10)}}function Ps(e){return e.split("; ").reduce(((e,t)=>{const[n,i]=t.split("=");return e[n]=i,e}),{})}function Ms(e,t,n){return function(e,t){return e.some((e=>"number"==typeof e?e===t:t>=e[0]&&t<=e[1]))}(e.failedRequestStatusCodes,t)&&(i=e.failedRequestTargets,s=n,i.some((e=>"string"==typeof e?s.includes(e):e.test(s))))&&!Mn(n,(0,c.KU)());var i,s}function Ds(e){const t=`HTTP Client Error with status code: ${e.status}`,n={message:t,exception:{values:[{type:"Error",value:t}]},request:{url:e.url,method:e.method,headers:e.requestHeaders,cookies:e.requestCookies},contexts:{response:{status_code:e.status,headers:e.responseHeaders,cookies:e.responseCookies,body_size:Os(e.responseHeaders)}}};return(0,C.M6)(n,{type:"http.client",handled:!1}),n}function qs(){const e=(0,c.KU)();return!!e&&Boolean(e.getOptions().sendDefaultPii)}(0,l.F)(Ls,js);const $s=Yt.OW,eo="ReportingObserver",to=new WeakMap,no=(0,l._C)(((e={})=>{const t=e.types||["crash","deprecation","intervention"];function n(e){if(to.has((0,c.KU)()))for(const t of e)(0,c.v4)((e=>{e.setExtra("url",t.url);const n=`ReportingObserver [${t.type}]`;let i="No details available";if(t.body){const n={};for(const e in t.body)n[e]=t.body[e];if(e.setExtra("body",n),"crash"===t.type){const e=t.body;i=[e.crashId||"",e.reason||""].join(" ").trim()||i}else i=t.body.message||i}(0,c.wd)(`${n}: ${i}`)}))}return{name:eo,setupOnce(){"ReportingObserver"in ks&&new $s.ReportingObserver(n,{buffered:!0,types:t}).observe()},setup(e){to.set(e,!0)}}})),io=((0,l.F)(eo,no),"RewriteFrames"),so=(0,l._C)(((e={})=>{const t=e.root,n=e.prefix||"app:///",i=e.iteratee||(e=>{if(!e.filename)return e;const i=/^[a-zA-Z]:\\/.test(e.filename)||e.filename.includes("\\")&&!e.filename.includes("/"),s=/^\//.test(e.filename);if(i||s){const s=i?e.filename.replace(/^[a-zA-Z]:/,"").replace(/\\/g,"/"):e.filename,o=t?function(e,t){e=Fi(e).slice(1),t=Fi(t).slice(1);const n=ki(e.split("/")),i=ki(t.split("/")),s=Math.min(n.length,i.length);let o=s;for(let e=0;ei(e)))}}return{name:io,setupOnce(){},processEvent(e){let t=e;return e.exception&&Array.isArray(e.exception.values)&&(t=function(e){try{return{...e,exception:{...e.exception,values:e.exception.values.map((e=>({...e,...e.stacktrace&&{stacktrace:s(e.stacktrace)}})))}}}catch(t){return e}}(t)),t}}})),oo=((0,l.F)(io,so),"SessionTiming"),ro=(0,l._C)((()=>{const e=Date.now();return{name:oo,setupOnce(){},processEvent(t){const n=Date.now();return{...t,extra:{...t.extra,"session:start":e,"session:duration":n-e,"session:end":n}}}}})),ao=((0,l.F)(oo,ro),[["january","1"],["february","2"],["march","3"],["april","4"],["may","5"],["june","6"],["july","7"],["august","8"],["september","9"],["october","10"],["november","11"],["december","12"],["jan","1"],["feb","2"],["mar","3"],["apr","4"],["may","5"],["jun","6"],["jul","7"],["aug","8"],["sep","9"],["oct","10"],["nov","11"],["dec","12"],["sunday","0"],["monday","1"],["tuesday","2"],["wednesday","3"],["thursday","4"],["friday","5"],["saturday","6"],["sun","0"],["mon","1"],["tue","2"],["wed","3"],["thu","4"],["fri","5"],["sat","6"]]);function co(e){return ao.reduce(((e,[t,n])=>e.replace(new RegExp(t,"gi"),n)),e)}const lo="Automatic instrumentation of CronJob only supports crontab string",go=Ji(),uo={...F,...o,...r},bo={instrumentCron:function(e,t){let n=!1;return new Proxy(e,{construct(e,i){const[s,o,r,a,l,...g]=i;if("string"!=typeof s)throw new Error(lo);if(n)throw new Error(`A job named '${t}' has already been scheduled`);n=!0;const d=co(s);return new e(s,(function(e,n){return(0,c.T$)(t,(()=>o(e,n)),{schedule:{type:"crontab",value:d},timezone:l||void 0})}),r,a,l,...g)},get:(e,i)=>"from"===i?i=>{const{cronTime:s,onTick:o,timeZone:r}=i;if("string"!=typeof s)throw new Error(lo);if(n)throw new Error(`A job named '${t}' has already been scheduled`);n=!0;const a=co(s);return i.onTick=(e,n)=>(0,c.T$)(t,(()=>o(e,n)),{schedule:{type:"crontab",value:a},timezone:r||void 0}),e.from(i)}:e[i]})},instrumentNodeCron:function(e){return new Proxy(e,{get:(e,t)=>"schedule"===t&&e.schedule?new Proxy(e.schedule,{apply(e,t,n){const[i,,s]=n;if(!(0,nn.z)([s,"optionalAccess",e=>e.name]))throw new Error('Missing "name" for scheduled job. A name is required for Sentry check-in monitoring.');return(0,c.T$)(s.name,(()=>e.apply(t,n)),{schedule:{type:"crontab",value:co(i)},timezone:(0,nn.z)([s,"optionalAccess",e=>e.timezone])})}}):e[t]})},instrumentNodeSchedule:function(e){return new Proxy(e,{get:(e,t)=>"scheduleJob"===t?new Proxy(e.scheduleJob,{apply(e,t,n){const[i,s]=n;if("string"!=typeof i||"string"!=typeof s)throw new Error("Automatic instrumentation of 'node-schedule' requires the first parameter of 'scheduleJob' to be a job name string and the second parameter to be a crontab string");const o=i,r=s;return(0,c.T$)(o,(()=>e.apply(t,n)),{schedule:{type:"crontab",value:co(r)}})}}):e[t]})}}},1615:(e,t,n)=>{"use strict";n.d(t,{M:()=>m,a:()=>h});var i=n(853);function s(e){const t=(0,i.z)(e);return null==t||t}var o=n(7016),r=n(2486),a=n(1535),c=n(6641),l=n(3741),g=n(5836),d=n(7412),u=n(6341),b=n(3903),I=n(3245);function p(e,...t){d.vF.log(`[ANR] ${e}`,...t)}function C(){const e=(0,r.m6)().getScopeData();return(0,a.Rg)(e,(0,c.rm)().getScopeData()),(0,a.Rg)(e,(0,l.o5)().getScopeData()),e.attachments=[],e.eventProcessors=[],e}e=n.hmd(e);const h=(0,g._C)(((t={})=>{if(I.S.major<16||16===I.S.major&&I.S.minor<17)throw new Error("ANR detection requires Node 16.17.0 or later");let r,a;return u.OW.__SENTRY_GET_SCOPES__=C,{name:"Anr",setupOnce(){},startWorker:()=>{r||a&&(r=async function(t,r){const a=t.getDsn();if(!a)return()=>{};const c=await async function(e){let t={message:"ANR"};const n={};for(const i of e.getEventProcessors()){if(null===t)break;t=await i(t,n)}return(0,i.z)([t,"optionalAccess",e=>e.contexts])||{}}(t);s([c,"access",e=>e.app,"optionalAccess",e=>delete e.app_memory]),s([c,"access",e=>e.device,"optionalAccess",e=>delete e.free_memory]);const g=t.getOptions(),u=t.getSdkMetadata()||{};u.sdk&&(u.sdk.integrations=g.integrations.map((e=>e.name)));const I={debug:d.vF.isEnabled(),dsn:a,environment:g.environment||"production",release:g.release,dist:g.dist,sdkMetadata:u,appRootPath:r.appRootPath,pollInterval:r.pollInterval||50,anrThreshold:r.anrThreshold||5e3,captureStackTrace:!!r.captureStackTrace,staticTags:r.staticTags||{},contexts:c};if(I.captureStackTrace){const e=n(264);e.url()||e.open(0)}const{Worker:C}=(0,b.fj)(e,"worker_threads"),h=new C(new o.URL("data:application/javascript;base64,aW1wb3J0IHsgU2Vzc2lvbiB9IGZyb20gJ2luc3BlY3Rvcic7CmltcG9ydCB7IHdv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7CiAgICB9IGNhdGNoIChlKSB7CiAgICAgIHRoaXMuX3JlamVjdChlKTsKICAgIH0KICB9CgogIC8qKiBKU0RvYyAqLwogICB0aGVuKAogICAgb25mdWxmaWxsZWQsCiAgICBvbnJlamVjdGVkLAogICkgewogICAgcmV0dXJuIG5ldyBTeW5jUHJvbWlzZSgocmVzb2x2ZSwgcmVqZWN0KSA9PiB7CiAgICAgIHRoaXMuX2hhbmRsZXJzLnB1c2goWwogICAgICAgIGZhbHNlLAogICAgICAgIHJlc3VsdCA9PiB7CiAgICAgICAgICBpZiAoIW9uZnVsZmlsbGVkKSB7CiAgICAgICAgICAgIC8vIFRPRE86IMKvXF8o44OEKV8vwq8KICAgICAgICAgICAgLy8gVE9ETzogRklYTUUKICAgICAgICAgICAgcmVzb2x2ZShyZXN1bHQgKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgcmVzb2x2ZShvbmZ1bGZpbGxlZChyZXN1bHQpKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIHJlamVjdChlKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgcmVhc29uID0+IHsKICAgICAgICAgIGlmICghb25yZWplY3RlZCkgewogICAgICAgICAgICByZWplY3QocmVhc29uKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgcmVzb2x2ZShvbnJlamVjdGVkKHJlYXNvbikpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgcmVqZWN0KGUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgXSk7CiAgICAgIHRoaXMuX2V4ZWN1dGVIYW5kbGVycygpOwogICAgfSk7CiAgfQoKICAvKiogSlNEb2MgKi8KICAgY2F0Y2goCiAgICBvbnJlamVjdGVkLAogICkgewogICAgcmV0dXJuIHRoaXMudGhlbih2YWwgPT4gdmFsLCBvbnJlamVjdGVkKTsKICB9CgogIC8qKiBKU0RvYyAqLwogICBmaW5hbGx5KG9uZmluYWxseSkgewogICAgcmV0dXJuIG5ldyBTeW5jUHJvbWlzZSgocmVzb2x2ZSwgcmVqZWN0KSA9PiB7CiAgICAgIGxldCB2YWw7CiAgICAgIGxldCBpc1JlamVjdGVkOwoKICAgICAgcmV0dXJuIHRoaXMudGhlbigKICAgICAgICB2YWx1ZSA9PiB7CiAgICAgICAgICBpc1JlamVjdGVkID0gZmFsc2U7CiAgICAgICAgICB2YWwgPSB2YWx1ZTsKICAgICAgICAgIGlmIChvbmZpbmFsbHkpIHsKICAgICAgICAgICAgb25maW5hbGx5KCk7CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICByZWFzb24gPT4gewogICAgICAgICAgaXNSZWplY3RlZCA9IHRydWU7CiAgICAgICAgICB2YWwgPSByZWFzb247CiAgICAgICAgICBpZiAob25maW5hbGx5KSB7CiAgICAgICAgICAgIG9uZmluYWxseSgpOwogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICkudGhlbigoKSA9PiB7CiAgICAgICAgaWYgKGlzUmVqZWN0ZWQpIHsKICAgICAgICAgIHJlamVjdCh2YWwpOwogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KCiAgICAgICAgcmVzb2x2ZSh2YWwgKTsKICAgICAgfSk7CiAgICB9KTsKICB9CgogIC8qKiBKU0RvYyAqLwogICAgX19pbml0KCkge3RoaXMuX3Jlc29sdmUgPSAodmFsdWUpID0+IHsKICAgIHRoaXMuX3NldFJlc3VsdChTdGF0ZXMuUkVTT0xWRUQsIHZhbHVlKTsKICB9O30KCiAgLyoqIEpTRG9jICovCiAgICBfX2luaXQyKCkge3RoaXMuX3JlamVjdCA9IChyZWFzb24pID0+IHsKICAgIHRoaXMuX3NldFJlc3VsdChTdGF0ZXMuUkVKRUNURUQsIHJlYXNvbik7CiAgfTt9CgogIC8qKiBKU0RvYyA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HVybiB0aGlzOwogIH0KCiAgLyoqCiAgICogQGluaGVyaXREb2MKICAgKi8KICAgc2V0VGFncyh0YWdzKSB7CiAgICB0aGlzLl90YWdzID0gewogICAgICAuLi50aGlzLl90YWdzLAogICAgICAuLi50YWdzLAogICAgfTsKICAgIHRoaXMuX25vdGlmeVNjb3BlTGlzdGVuZXJzKCk7CiAgICByZXR1cm4gdGhpczsKICB9CgogIC8qKgogICAqIEBpbmhlcml0RG9jCiAgICovCiAgIHNldFRhZyhrZXksIHZhbHVlKSB7CiAgICB0aGlzLl90YWdzID0geyAuLi50aGlzLl90YWdzLCBba2V5XTogdmFsdWUgfTsKICAgIHRoaXMuX25vdGlmeVNjb3BlTGlzdGVuZXJzKCk7CiAgICByZXR1cm4gdGhpczsKICB9CgogIC8qKgogICAqIEBpbmhlcml0RG9jCiAgICovCiAgIHNldEV4dHJhcyhleHRyYXMpIHsKICAgIHRoaXMuX2V4dHJhID0gewogICAgICAuLi50aGlzLl9leHRyYSwKICAgICAgLi4uZXh0cmFzLAogICAgfTsKICAgIHRoaXMuX25vdGlmeVNjb3BlTGlzdGVuZXJzKCk7CiAgICByZXR1cm4gdGhpczsKICB9CgogIC8qKgogICAqIEBpbmhlcml0RG9jCiAgICovCiAgIHNldEV4dHJhKGtleSwgZXh0cmEpIHsKICAgIHRoaXMuX2V4dHJhID0geyAuLi50aGlzLl9leHRyYSwgW2tleV06IGV4dHJhIH07CiAgICB0aGlzLl9ub3RpZnlTY29wZUxpc3RlbmVycygpOwogICAgcmV0dXJuIHRoaXM7CiAgfQoKICAvKioKICAgKiBAaW5oZXJpdERvYwogICAqLwogICBzZXRGaW5nZXJwcmludChmaW5nZXJwcmludCkgewogICAgdGhpcy5fZmluZ2VycHJpbnQgPSBmaW5nZXJwcmludDsKICAgIHRoaXMuX25vdGlmeVNjb3BlTGlzdGVuZXJzKCk7CiAgICByZXR1cm4gdGhpczsKICB9CgogIC8qKgogICAqIEBpbmhlcml0RG9jCiAgICovCiAgIHNld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aGVyaXREb2MKICAgKi8KICAgZ2V0TGFzdEJyZWFkY3J1bWIoKSB7CiAgICByZXR1cm4gdGhpcy5fYnJlYWRjcnVtYnNbdGhpcy5fYnJlYWRjcnVtYnMubGVuZ3RoIC0gMV07CiAgfQoKICAvKioKICAgKiBAaW5oZXJpdERvYwogICAqLwogICBjbGVhckJyZWFkY3J1bWJzKCkgewogICAgdGhpcy5fYnJlYWRjcnVtYnMgPSBbXTsKICAgIHRoaXMuX25vdGlmeVNjb3BlTGlzdGVuZXJzKCk7CiAgICByZXR1cm4gdGhpczsKICB9CgogIC8qKgogICAqIEBpbmhlcml0RG9jCiAgICovCiAgIGFkZEF0dGFjaG1lbnQoYXR0YWNobWVudCkgewogICAgdGhpcy5fYXR0YWNobWVudHMucHVzaChhdHRhY2htZW50KTsKICAgIHJldHVybiB0aGlzOwogIH0KCiAgLyoqCiAgICogQGluaGVyaXREb2MKICAgKiBAZGVwcmVjYXRlZCBVc2UgYGdldFNjb3BlRGF0YSgpYCBpbnN0ZWFkLgogICAqLwogICBnZXRBdHRhY2htZW50cygpIHsKICAgIGNvbnN0IGRhdGEgPSB0aGlzLmdldFNjb3BlRGF0YSgpOwoKICAgIHJldHVybiBkYXRhLmF0dGFjaG1lbnRzOwogIH0KCiAgLyoqCiAgICogQGluaGVyaXREb2MKICAgKi8KICAgY2xlYXJBdHRhY2htZW50cygpIHsKICAgIHRoaXMuX2F0dGFjaG1lbnRzID0gW107CiAgICByZXR1cm4gdGhpczsKICB9CgogIC8qKiBAaW5oZXJpdERvYyAqLwogICBnZXRTY29wZURhdGEoKSB7CiAgICBjb25zdCB7CiAgICAgIF9icmVhZGNydW1icywKICAgICAgX2F0dGFjaG1lbnRzLAogICAgICBfY29udGV4dHMsCiAgICAgIF90YWdzLAogICAgICBfZXh0cmEsCiAgICAgIF91c2VyLAogICAgICBfbGV2ZWwsCiAgICAgIF9maW5nZXJwcmludCwKICAgICAgX2V2ZW50UHJvY2Vzc29ycywKICAgICAgX3Byb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qIGBgYAogICAqCiAgICogaW5zdGVhZCBpbml0aWFsaXplIHRoZSBjbGllbnQgYXMgZm9sbG93czoKICAgKgogICAqIGBgYAogICAqIC8vIE5FVwogICAqIFNlbnRyeS53aXRoSXNvbGF0aW9uU2NvcGUoKCkgPT4gewogICAqICAgIFNlbnRyeS5zZXRDdXJyZW50Q2xpZW50KGNsaWVudCk7CiAgICogICAgY2xpZW50LmluaXQoKTsKICAgKiB9KTsKICAgKiBgYGAKICAgKgogICAqIElmIHlvdSBhcmUgdXNpbmcgdGhlIEh1YiB0byBjYXB0dXJlIGV2ZW50cyBsaWtlIHNvOgogICAqCiAgICogYGBgCiAgICogLy8gT0xECiAgICogY29uc3QgY2xpZW50ID0gbmV3IENsaWVudCgpOwogICAqIGNvbnN0IGh1YiA9IG5ldyBIdWIoY2xpZW50KTsKICAgKiBodWIuY2FwdHVyZUV4Y2VwdGlvbigpCiAgICogYGBgCiAgICoKICAgKiBpbnN0ZWFkIGNhcHR1cmUgaXNvbGF0ZWQgZXZlbnRzIGFzIGZvbGxvd3M6CiAgICoKICAgKiBgYGAKICAgKiAvLyBORVcKICAgKiBjb25zdCBjbGllbnQgPSBuZXcgQ2xpZW50KCk7CiAgICogY29uc3Qgc2NvcGUgPSBuZXcgU2NvcGUoKTsKICAgKiBzY29wZS5zZXRDbGllbnQoY2xpZW50KTsKICAgKiBzY29wZS5jYXB0dXJlRXhjZXB0aW9uKCk7CiAgICogYGBgCiAgICovCiAgIGNvbnN0cnVjdG9yKAogICAgY2xpZW50LAogICAgc2NvcGUsCiAgICBpc29sYXRpb25TY29wZSwKICAgICAgX3ZlcnNpb24gPSBBUElfVkVSU0lPTiwKICApIHt0aGlzLl92ZXJzaW9uID0gX3ZlcnNpb247CiAgICBsZXQgYXNzaWduZWRTY29wZTsKICAgIGlmICghc2NvcGUpIHsKICAgICAgYXNzaWduZWRTY29wZSA9IG5ldyBTY29wZSgpOwogICAgICBhc3NpZ25lZFNjb3BlLnNldENsaWVudChjbGll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2F0aW9uL2RlcHJlY2F0aW9uCiAgICAgIHRoaXMucG9wU2NvcGUoKTsKICAgICAgdGhyb3cgZTsKICAgIH0KCiAgICBpZiAoaXNUaGVuYWJsZShtYXliZVByb21pc2VSZXN1bHQpKSB7CiAgICAgIC8vIEB0cy1leHBlY3QtZXJyb3IgLSBpc1RoZW5hYmxlIHJldHVybnMgdGhlIHdyb25nIHR5cGUKICAgICAgcmV0dXJuIG1heWJlUHJvbWlzZVJlc3VsdC50aGVuKAogICAgICAgIHJlcyA9PiB7CiAgICAgICAgICAvLyBlc2xpbnQtZGlzYWJsZS1uZXh0LWxpbmUgZGVwcmVjYXRpb24vZGVwcmVjYXRpb24KICAgICAgICAgIHRoaXMucG9wU2NvcGUoKTsKICAgICAgICAgIHJldHVybiByZXM7CiAgICAgICAgfSwKICAgICAgICBlID0+IHsKICAgICAgICAgIC8vIGVzbGludC1kaXNhYmxlLW5leHQtbGluZSBkZXByZWNhdGlvbi9kZXByZWNhdGlvbgogICAgICAgICAgdGhpcy5wb3BTY29wZSgpOwogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9LAogICAgICApOwogICAgfQoKICAgIC8vIGVzbGludC1kaXNhYmxlLW5leHQtbGluZSBkZXByZWNhdGlvbi9kZXByZWNhdGlvbgogICAgdGhpcy5wb3BTY29wZSgpOwogICAgcmV0dXJuIG1heWJlUHJvbWlzZVJlc3VsdDsKICB9CgogIC8qKgogICAqIEBpbmhlcml0RG9jCiAgICoKICAgKiBAZGVwcmVjYXRlZCBVc2UgYFNlbnRyeS5nZXRDbGllbnQoKWAgaW5zdGVhZC4KICAgKi8KICAgZ2V0Q2xpZW50KCkgewogICAgLy8gZXNsaW50LWRpc2FibGUtbmV4dC1saW5lIGRlcHJlY2F0aW9uL2RlcHJlY2F0aW9uCiAgICByZXR1cm4gdGhpcy5nZXRTdGFja1RvcCgpLmNsaWVudCA7CiAgfQoKICAvKioKICAgKiBSZXR1cm5zIHRoZSBzY29wZSBvZiB0aGUgdG9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ZXNwb25zZTogIiR7aGVhZGVyfSJgKSk7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGtleSA9IGhlYWRlci5zbGljZSgwLCBmaXJzdENvbG9uKS50b0xvd2VyQ2FzZSgpOwogICAgICAgIGNvbnN0IHZhbHVlID0gaGVhZGVyLnNsaWNlKGZpcnN0Q29sb24gKyAxKS50cmltU3RhcnQoKTsKICAgICAgICBjb25zdCBjdXJyZW50ID0gaGVhZGVyc1trZXldOwogICAgICAgIGlmICh0eXBlb2YgY3VycmVudCA9PT0gJ3N0cmluZycpIHsKICAgICAgICAgIGhlYWRlcnNba2V5XSA9IFtjdXJyZW50LCB2YWx1ZV07CiAgICAgICAgfSBlbHNlIGlmIChBcnJheS5pc0FycmF5KGN1cnJlbnQpKSB7CiAgICAgICAgICBjdXJyZW50LnB1c2godmFsdWUpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBoZWFkZXJzW2tleV0gPSB2YWx1ZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZGVidWckMSgnZ290IHByb3h5IHNlcnZlciByZXNwb25zZTogJW8gJW8nLCBmaXJzdExpbmUsIGhlYWRlcnMpOwogICAgICBjbGVhbnVwKCk7CiAgICAgIHJlc29sdmUoewogICAgICAgIGNvbm5lY3Q6IHsKICAgICAgICAgIHN0YXR1c0NvZGUsCiAgICAgICAgICBzdGF0dXNUZXh0LAogICAgICAgICAgaGVhZGVycywKICAgICAgICB9LAogICAgICAgIGJ1ZmZlcmVkLAogICAgICB9KTsKICAgIH0KCiAgICBzb2NrZXQub24oJ2Vycm9yJywgb25lcnJvcik7CiAgICBzb2NrZXQub24oJ2VuZCcsIG9uZW5kKTsKCiAgICByZWFkKCk7CiAgfSk7Cn0KCmZ1bmN0aW9uIF9udWxsaXNoQ29hbGVzY2UkMShsaHMsIHJoc0ZuKSB7IGlmIChsaHMgIT0gbnVsbCkgeyByZXR1cm4gbGhzOyB9IGVsc2UgeyByZXR1cm4gcmhzRm4oKTsgfSB9IGZ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BoZWFkZXJzWydjb250ZW50LWVuY29kaW5nJ10gPSAnZ3ppcCc7CiAgICAgICAgYm9keSA9IGJvZHkucGlwZShjcmVhdGVHemlwKCkpOwogICAgICB9CgogICAgICBjb25zdCByZXEgPSBodHRwTW9kdWxlLnJlcXVlc3QoCiAgICAgICAgewogICAgICAgICAgbWV0aG9kOiAnUE9TVCcsCiAgICAgICAgICBhZ2VudCwKICAgICAgICAgIGhlYWRlcnMsCiAgICAgICAgICBob3N0bmFtZSwKICAgICAgICAgIHBhdGg6IGAke3BhdGhuYW1lfSR7c2VhcmNofWAsCiAgICAgICAgICBwb3J0LAogICAgICAgICAgcHJvdG9jb2wsCiAgICAgICAgICBjYTogb3B0aW9ucy5jYUNlcnRzLAogICAgICAgIH0sCiAgICAgICAgcmVzID0+IHsKICAgICAgICAgIHJlcy5vbignZGF0YScsICgpID0+IHsKICAgICAgICAgICAgLy8gRHJhaW4gc29ja2V0CiAgICAgICAgICB9KTsKCiAgICAgICAgICByZXMub24oJ2VuZCcsICgpID0+IHsKICAgICAgICAgICAgLy8gRHJhaW4gc29ja2V0CiAgICAgICAgICB9KTsKCiAgICAgICAgICByZXMuc2V0RW5jb2RpbmcoJ3V0ZjgnKTsKCiAgICAgICAgICAvLyAiS2V5LXZhbHVlIHBhaXJzIG9mIGhlYWRlciBuYW1lcyBhbmQgdmFsdWVzLiBIZWFkZXIgbmFtZXMgYXJlIGxvd2VyLWNhc2VkLiIKICAgICAgICAgIC8vIGh0dHBzOi8vbm9kZWpzLm9yZy9hcGkvaHR0cC5odG1sI2h0dHBfbWVzc2FnZV9oZWFkZXJzCiAgICAgICAgICBjb25zdCByZXRyeUFmdGVySGVhZGVyID0gX251bGxpc2hDb2FsZXNjZShyZXMuaGVhZGVyc1sncmV0cnktYWZ0ZXInXSwgKCkgPT4gKCBudWxsKSk7CiAgICAgICAgICBjb25zdCByYXRlTGltaXRzSGVhZGVyID0gX251bGxpc2hDb2FsZXNjZShyZXMuaGVhZGVyc1sneC1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zc2lvbik7CiAgfQoKICBwb2xsKCk7Cn0pXSk7"),{workerData:I});process.on("exit",(()=>{h.terminate()}));const m=setInterval((()=>{try{const e=(0,l.o5)().getSession(),t=e?{...e,toJSON:void 0}:void 0;h.postMessage({session:t})}catch(e){}}),I.pollInterval);return m.unref(),h.on("message",(e=>{"session-ended"===e&&(p("ANR event sent from ANR worker. Clearing session in this thread."),(0,l.o5)().setSession(void 0))})),h.once("error",(e=>{clearInterval(m),p("ANR worker error",e)})),h.once("exit",(e=>{clearInterval(m),p("ANR worker exit",e)})),h.unref(),()=>{h.terminate(),clearInterval(m)}}(a,t))},stopWorker:()=>{r&&r.then((e=>{e(),r=void 0}))},setup(e){a=e,setImmediate((()=>this.startWorker()))}}})),m=(0,g.F)("Anr",h)},3245:(e,t,n)=>{"use strict";n.d(t,{S:()=>i});const i=(0,n(6936).kf)(process.versions.node)},2786:(e,t,n)=>{"use strict";n.d(t,{j:()=>s});var i=n(3903);e=n.hmd(e);const s=[()=>new((0,i.fj)(e,"./apollo").Apollo),()=>new((0,i.fj)(e,"./apollo").Apollo)({useNestjs:!0}),()=>new((0,i.fj)(e,"./graphql").GraphQL),()=>new((0,i.fj)(e,"./mongo").Mongo),()=>new((0,i.fj)(e,"./mongo").Mongo)({mongoose:!0}),()=>new((0,i.fj)(e,"./mysql").Mysql),()=>new((0,i.fj)(e,"./postgres").Postgres)]},5664:(e,t,n)=>{"use strict";n.r(t),n.d(t,{BROWSER_TRACING_INTEGRATION_ID:()=>Ht,BrowserTracing:()=>Wt,IdleTransaction:()=>Ft,Integrations:()=>zt,Span:()=>Xt,SpanStatus:()=>Jt,TRACEPARENT_REGEXP:()=>Kt,Transaction:()=>Yt,addExtensionMethods:()=>ft,defaultRequestInstrumentationOptions:()=>St,extractTraceparentData:()=>vt,getActiveTransaction:()=>Vt,hasTracingEnabled:()=>Nt,instrumentOutgoingRequests:()=>kt,spanStatusfromHttpCode:()=>Rt,startIdleTransaction:()=>_t,stripUrlQueryAndFragment:()=>wt});var i=n(683),s=n(1763),o=n(1692),r=n(5071),a=n(9071),c=n(6202),l=n(1206),g=n(138),d=n(2231);const u=(0,d.VZ)(),b=80;function I(e,t={}){if(!e)return"";try{let n=e;const i=5,s=[];let o=0,r=0;const a=" > ",c=a.length;let l;const g=Array.isArray(t)?t:t.keyAttrs,d=!Array.isArray(t)&&t.maxStringLength||b;for(;n&&o++1&&r+s.length*c+l.length>=d));)s.push(l),r+=l.length,n=n.parentNode;return s.reverse().join(a)}catch(e){return""}}function p(e,t){const n=e,i=[];let s,o,r,a,c;if(!n||!n.tagName)return"";if(u.HTMLElement&&n instanceof HTMLElement&&n.dataset&&n.dataset.sentryComponent)return n.dataset.sentryComponent;i.push(n.tagName.toLowerCase());const l=t&&t.length?t.filter((e=>n.getAttribute(e))).map((e=>[e,n.getAttribute(e)])):null;if(l&&l.length)l.forEach((e=>{i.push(`[${e[0]}="${e[1]}"]`)}));else if(n.id&&i.push(`#${n.id}`),s=n.className,s&&(0,g.Kg)(s))for(o=s.split(/\s+/),c=0;c{let i,s;return o=>{t.value>=0&&(o||n)&&(s=t.value-(i||0),(s||void 0===i)&&(i=t.value,t.delta=s,e(t)))}},B=()=>y.__WEB_VITALS_POLYFILL__?y.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||(()=>{const e=y.performance.timing,t=y.performance.navigation.type,n={entryType:"navigation",startTime:0,type:2==t?"back_forward":1===t?"reload":"navigate"};for(const t in e)"navigationStart"!==t&&"toJSON"!==t&&(n[t]=Math.max(e[t]-e.navigationStart,0));return n})()):y.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0],A=()=>{const e=B();return e&&e.activationStart||0},W=(e,t)=>{const n=B();let i="navigate";return n&&(i=y.document&&y.document.prerendering||A()>0?"prerender":n.type.replace(/_/g,"-")),{name:e,value:void 0===t?-1:t,rating:"good",delta:0,entries:[],id:`v3-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:i}},f=(e,t,n)=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){const i=new PerformanceObserver((e=>{t(e.getEntries())}));return i.observe(Object.assign({type:e,buffered:!0},n||{})),i}}catch(e){}},V=(e,t)=>{const n=i=>{"pagehide"!==i.type&&"hidden"!==y.document.visibilityState||(e(i),t&&(removeEventListener("visibilitychange",n,!0),removeEventListener("pagehide",n,!0)))};y.document&&(addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0))},v=(e,t={})=>{const n=W("CLS",0);let i,s=0,o=[];const r=e=>{e.forEach((e=>{if(!e.hadRecentInput){const t=o[0],r=o[o.length-1];s&&0!==o.length&&e.startTime-r.startTime<1e3&&e.startTime-t.startTime<5e3?(s+=e.value,o.push(e)):(s=e.value,o=[e]),s>n.value&&(n.value=s,n.entries=o,i&&i())}}))},a=f("layout-shift",r);if(a){i=G(e,n,t.reportAllChanges);const s=()=>{r(a.takeRecords()),i(!0)};return V(s),s}};let R=-1;const Y=()=>(R<0&&(y.document&&y.document.visibilityState&&(R="hidden"!==y.document.visibilityState||y.document.prerendering?1/0:0),V((({timeStamp:e})=>{R=e}),!0)),{get firstHiddenTime(){return R}}),X=e=>{const t=Y(),n=W("FID");let i;const s=e=>{e.startTime{e.forEach(s)},r=f("first-input",o);i=G(e,n),r&&V((()=>{o(r.takeRecords()),r.disconnect()}),!0)};let H=0,S=1/0,N=0;const w=e=>{e.forEach((e=>{e.interactionId&&(S=Math.min(S,e.interactionId),N=Math.max(N,e.interactionId),H=N?(N-S)/7+1:0)}))};let K;const F=()=>{"interactionCount"in performance||K||(K=f("event",w,{type:"event",buffered:!0,durationThreshold:0}))},k=()=>K?H:performance.interactionCount||0,_=[],J={},z=e=>{const t=_[_.length-1],n=J[e.interactionId];if(n||_.length<10||e.duration>t.latency){if(n)n.entries.push(e),n.latency=Math.max(n.latency,e.duration);else{const t={id:e.interactionId,latency:e.duration,entries:[e]};J[t.id]=t,_.push(t)}_.sort(((e,t)=>t.latency-e.latency)),_.splice(10).forEach((e=>{delete J[e.id]}))}},U=(e,t)=>{t=t||{},F();const n=W("INP");let i;const s=e=>{e.forEach((e=>{e.interactionId&&z(e),"first-input"===e.entryType&&!_.some((t=>t.entries.some((t=>e.duration===t.duration&&e.startTime===t.startTime))))&&z(e)}));const t=(()=>{const e=Math.min(_.length-1,Math.floor(k()/50));return _[e]})();t&&t.latency!==n.value&&(n.value=t.latency,n.entries=t.entries,i())},o=f("event",s,{durationThreshold:t.durationThreshold||40});i=G(e,n,t.reportAllChanges),o&&(o.observe({type:"first-input",buffered:!0}),V((()=>{s(o.takeRecords()),n.value<0&&k()>0&&(n.value=0,n.entries=[]),i(!0)})))},x={},T=e=>{const t=Y(),n=W("LCP");let i;const s=e=>{const s=e[e.length-1];if(s){const e=Math.max(s.startTime-A(),0);e{x[n.id]||(s(o.takeRecords()),o.disconnect(),x[n.id]=!0,i(!0))};return["keydown","click"].forEach((e=>{y.document&&addEventListener(e,t,{once:!0,capture:!0})})),V(t,!0),t}},E=e=>{y.document&&(y.document.prerendering?addEventListener("prerenderingchange",(()=>E(e)),!0):"complete"!==y.document.readyState?addEventListener("load",(()=>E(e)),!0):setTimeout(e,0))},Q=(e,t)=>{t=t||{};const n=W("TTFB"),i=G(e,n,t.reportAllChanges);E((()=>{const e=B();if(e){if(n.value=Math.max(e.responseStart-A(),0),n.value<0||n.value>performance.now())return;n.entries=[e],i(!0)}}))},L={},j={};let O,P,M,D,q;function $(e,t){return ae(e,t),j[e]||(function(e){const t={};"event"===e&&(t.durationThreshold=0),f(e,(t=>{ee(e,{entries:t})}),t)}(e),j[e]=!0),ce(e,t)}function ee(e,t){const n=L[e];if(n&&n.length)for(const i of n)try{i(t)}catch(t){h&&c.vF.error(`Error while triggering instrumentation handler.\nType: ${e}\nName: ${(0,Z.qQ)(i)}\nError:`,t)}}function te(){return v((e=>{ee("cls",{metric:e}),O=e}),{reportAllChanges:!0})}function ne(){return X((e=>{ee("fid",{metric:e}),P=e}))}function ie(){return T((e=>{ee("lcp",{metric:e}),M=e}))}function se(){return Q((e=>{ee("ttfb",{metric:e}),D=e}))}function oe(){return U((e=>{ee("inp",{metric:e}),q=e}))}function re(e,t,n,i,s=!1){let o;return ae(e,t),j[e]||(o=n(),j[e]=!0),i&&t({metric:i}),ce(e,t,s?o:void 0)}function ae(e,t){L[e]=L[e]||[],L[e].push(t)}function ce(e,t,n){return()=>{n&&n();const i=L[e];if(!i)return;const s=i.indexOf(t);-1!==s&&i.splice(s,1)}}var le=n(7037);function ge(e){return[{type:"span"},e]}var de=n(5177),ue=n(6056),be=n(7567);function Ie(e){if(!e)return{};const t=e.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)return{};const n=t[6]||"",i=t[8]||"";return{host:t[4],path:t[5],protocol:t[2],search:n,hash:i,relative:t[5]+n+i}}function pe(e){return e.split(/[\?#]/,1)[0]}function Ce(e){return e.split(/\\?\//).filter((e=>e.length>0&&","!==e)).length}function he(e){return"number"==typeof e&&isFinite(e)}function me(e,{startTimestamp:t,...n}){return t&&e.startTimestamp>t&&(e.startTimestamp=t),e.startChild({startTimestamp:t,...n})}const ye=2147483647;function Ze(e){return e/1e3}function Ge(){return y&&y.addEventListener&&y.performance}let Be,Ae,We=0,fe={};function Ve(){const e=Ge();if(e&&be.k3){e.mark&&y.performance.mark("sentry-tracing-init");const t=re("fid",(({metric:e})=>{const t=e.entries[e.entries.length-1];if(!t)return;const n=Ze(be.k3),i=Ze(t.startTime);h&&c.vF.log("[Measurements] Adding FID"),fe.fid={value:e.value,unit:"millisecond"},fe["mark.fid"]={value:n+i,unit:"second"}}),ne,P),n=function(e,t=!1){return re("cls",e,te,O,t)}((({metric:e})=>{const t=e.entries[e.entries.length-1];t&&(h&&c.vF.log("[Measurements] Adding CLS"),fe.cls={value:e.value,unit:""},Ae=t)}),!0),i=function(e,t=!1){return re("lcp",e,ie,M,t)}((({metric:e})=>{const t=e.entries[e.entries.length-1];t&&(h&&c.vF.log("[Measurements] Adding LCP"),fe.lcp={value:e.value,unit:"millisecond"},Be=t)}),!0),s=re("ttfb",(({metric:e})=>{e.entries[e.entries.length-1]&&(h&&c.vF.log("[Measurements] Adding TTFB"),fe.ttfb={value:e.value,unit:"millisecond"})}),se,D);return()=>{t(),n(),i(),s()}}return()=>{}}const ve={click:"click",pointerdown:"click",pointerup:"click",mousedown:"click",mouseup:"click",touchstart:"click",touchend:"click",mouseover:"hover",mouseout:"hover",mouseenter:"hover",mouseleave:"hover",pointerover:"hover",pointerout:"hover",pointerenter:"hover",pointerleave:"hover",dragstart:"drag",dragend:"drag",drag:"drag",dragenter:"drag",dragleave:"drag",dragover:"drag",drop:"drag",keydown:"press",keyup:"press",keypress:"press",input:"press"};function Re(e,t,n,i,s,o){const r=o?t[o]:t[`${n}End`],a=t[`${n}Start`];a&&r&&me(e,{op:"browser",origin:"auto.browser.browser.metrics",description:s||n,startTimestamp:i+Ze(a),endTimestamp:i+Ze(r)})}function Ye(e,t,n,i){const s=t[n];null!=s&&s{const t={...s,endTimestamp:Date.now(),response:e};return(0,_e.aj)("fetch",t),e}),(e=>{const t={...s,endTimestamp:Date.now(),error:e};throw(0,_e.aj)("fetch",t),e}))}}))}function ze(e,t){return!!e&&"object"==typeof e&&!!e[t]}function Ue(e){return"string"==typeof e?e:e?ze(e,"url")?e.url:e.toString?e.toString():"":""}const xe=d.OW,Te="__sentry_xhr_v3__";function Ee(){if(!xe.XMLHttpRequest)return;const e=XMLHttpRequest.prototype;(0,we.GS)(e,"open",(function(e){return function(...t){const n=Date.now(),i=(0,g.Kg)(t[0])?t[0].toUpperCase():void 0,s=function(e){if((0,g.Kg)(e))return e;try{return e.toString()}catch(e){}}(t[1]);if(!i||!s)return e.apply(this,t);this[Te]={method:i,url:s,request_headers:{}},"POST"===i&&s.match(/sentry_key/)&&(this.__sentry_own_request__=!0);const o=()=>{const e=this[Te];if(e&&4===this.readyState){try{e.status_code=this.status}catch(e){}const t={args:[i,s],endTimestamp:Date.now(),startTimestamp:n,xhr:this};(0,_e.aj)("xhr",t)}};return"onreadystatechange"in this&&"function"==typeof this.onreadystatechange?(0,we.GS)(this,"onreadystatechange",(function(e){return function(...t){return o(),e.apply(this,t)}})):this.addEventListener("readystatechange",o),(0,we.GS)(this,"setRequestHeader",(function(e){return function(...t){const[n,i]=t,s=this[Te];return s&&(0,g.Kg)(n)&&(0,g.Kg)(i)&&(s.request_headers[n.toLowerCase()]=i),e.apply(this,t)}})),e.apply(this,t)}})),(0,we.GS)(e,"send",(function(e){return function(...t){const n=this[Te];if(!n)return e.apply(this,t);void 0!==t[0]&&(n.body=t[0]);const i={args:[n.method,n.url],startTimestamp:Date.now(),xhr:this};return(0,_e.aj)("xhr",i),e.apply(this,t)}}))}var Qe=n(8562);const Le=["localhost",/^\/(?!\/)/],je={traceFetch:!0,traceXHR:!0,enableHTTPTimings:!0,tracingOrigins:Le,tracePropagationTargets:Le};function Oe(e){const{traceFetch:t,traceXHR:n,tracePropagationTargets:i,tracingOrigins:s,shouldCreateSpanForRequest:o,enableHTTPTimings:c}={traceFetch:je.traceFetch,traceXHR:je.traceXHR,...e},d="function"==typeof o?o:e=>!0,u=e=>function(e,t){return function(e,t=[],n=!1){return t.some((t=>function(e,t,n=!1){return!!(0,g.Kg)(e)&&((0,g.gd)(t)?t.test(e):!!(0,g.Kg)(t)&&(n?e===t:e.includes(t)))}(e,t,n)))}(e,t||Le)}(e,i||s),b={};var I;t&&function(e){const t="fetch";(0,_e.s5)(t,(e=>{const t=function(e,t,n,i,s="auto.http.browser"){if(!(0,de.w)()||!e.fetchData)return;const o=t(e.fetchData.url);if(e.endTimestamp&&o){const t=e.fetchData.__span;if(!t)return;const n=i[t];return void(n&&(function(e,t){if(t.response){(0,Xe.N8)(e,t.response.status);const n=t.response&&t.response.headers&&t.response.headers.get("content-length");if(n){const t=parseInt(n);t>0&&e.setAttribute("http.response_content_length",t)}}else t.error&&e.setStatus("internal_error");e.end()}(n,e),delete i[t]))}const c=(0,a.o5)(),d=(0,a.KU)(),{method:u,url:b}=e.fetchData,I=function(e){try{return new URL(e).href}catch(e){return}}(b),p=I?Ie(I).host:void 0,C=o?(0,Se.Uk)({name:`${u} ${b}`,onlyIfParent:!0,attributes:{url:b,type:"fetch","http.method":u,"http.url":I,"server.address":p,[r.JD]:s},op:"http.client"}):void 0;if(C&&(e.fetchData.__span=C.spanContext().spanId,i[C.spanContext().spanId]=C),n(e.fetchData.url)&&d){const t=e.args[0];e.args[1]=e.args[1]||{};const n=e.args[1];n.headers=function(e,t,n,i,s){const o=s||n.getSpan(),r=(0,He.rm)(),{traceId:a,spanId:c,sampled:d,dsc:u}={...r.getPropagationContext(),...n.getPropagationContext()},b=o?(0,m.Qh)(o):(0,l.TC)(a,c,d),I=(0,Qe.De)(u||(o?(0,Ne.k)(o):(0,Ne.l)(a,t,n))),p=i.headers||("undefined"!=typeof Request&&(0,g.tH)(e,Request)?e.headers:void 0);if(p){if("undefined"!=typeof Headers&&(0,g.tH)(p,Headers)){const e=new Headers(p);return e.append("sentry-trace",b),I&&e.append(Qe.hF,I),e}if(Array.isArray(p)){const e=[...p,["sentry-trace",b]];return I&&e.push([Qe.hF,I]),e}{const e="baggage"in p?p.baggage:void 0,t=[];return Array.isArray(e)?t.push(...e):e&&t.push(e),I&&t.push(I),{...p,"sentry-trace":b,baggage:t.length>0?t.join(","):void 0}}}return{"sentry-trace":b,baggage:I}}(t,d,c,n,C)}return C}(e,d,u,b);if(t){const n=De(e.fetchData.url),i=n?Ie(n).host:void 0;t.setAttributes({"http.url":n,"server.address":i})}c&&t&&Pe(t)})),(0,_e.AS)(t,Je)}(),n&&(I=e=>{const t=function(e,t,n,i){const s=e.xhr,o=s&&s[Te];if(!(0,de.w)()||!s||s.__sentry_own_request__||!o)return;const c=t(o.url);if(e.endTimestamp&&c){const e=s.__sentry_xhr_span_id__;if(!e)return;const t=i[e];return void(t&&void 0!==o.status_code&&((0,Xe.N8)(t,o.status_code),t.end(),delete i[e]))}const g=(0,a.o5)(),d=(0,He.rm)(),u=De(o.url),b=u?Ie(u).host:void 0,I=c?(0,Se.Uk)({name:`${o.method} ${o.url}`,onlyIfParent:!0,attributes:{type:"xhr","http.method":o.method,"http.url":u,url:o.url,"server.address":b,[r.JD]:"auto.http.browser"},op:"http.client"}):void 0;I&&(s.__sentry_xhr_span_id__=I.spanContext().spanId,i[s.__sentry_xhr_span_id__]=I);const p=(0,a.KU)();if(s.setRequestHeader&&n(o.url)&&p){const{traceId:e,spanId:t,sampled:n,dsc:i}={...d.getPropagationContext(),...g.getPropagationContext()};!function(e,t,n){try{e.setRequestHeader("sentry-trace",t),n&&e.setRequestHeader(Qe.hF,n)}catch(e){}}(s,I?(0,m.Qh)(I):(0,l.TC)(e,t,n),(0,Qe.De)(i||(I?(0,Ne.k)(I):(0,Ne.l)(e,p,g))))}return I}(e,d,u,b);c&&t&&Pe(t)},(0,_e.s5)("xhr",I),(0,_e.AS)("xhr",Ee))}function Pe(e){const{url:t}=(0,m.et)(e).data||{};if(!t||"string"!=typeof t)return;const n=$("resource",(({entries:i})=>{i.forEach((i=>{(function(e){return"resource"===e.entryType&&"initiatorType"in e&&"string"==typeof e.nextHopProtocol&&("fetch"===e.initiatorType||"xmlhttprequest"===e.initiatorType)})(i)&&i.name.endsWith(t)&&(function(e){const{name:t,version:n}=function(e){let t="unknown",n="unknown",i="";for(const s of e){if("/"===s){[t,n]=e.split("/");break}if(!isNaN(Number(s))){t="h"===i?"http":i,n=e.split(i)[1];break}i+=s}return i===e&&(t=i),{name:t,version:n}}(e.nextHopProtocol),i=[];return i.push(["network.protocol.version",n],["network.protocol.name",t]),be.k3?[...i,["http.request.redirect_start",Me(e.redirectStart)],["http.request.fetch_start",Me(e.fetchStart)],["http.request.domain_lookup_start",Me(e.domainLookupStart)],["http.request.domain_lookup_end",Me(e.domainLookupEnd)],["http.request.connect_start",Me(e.connectStart)],["http.request.secure_connection_start",Me(e.secureConnectionStart)],["http.request.connection_end",Me(e.connectEnd)],["http.request.request_start",Me(e.requestStart)],["http.request.response_start",Me(e.responseStart)],["http.request.response_end",Me(e.responseEnd)]]:i}(i).forEach((t=>e.setAttribute(...t))),setTimeout(n))}))}))}function Me(e=0){return((be.k3||performance.timeOrigin)+e)/1e3}function De(e){try{return new URL(e,y.location.origin).href}catch(e){return}}const qe=(0,d.VZ)(),$e=d.OW;let et;function tt(){if(!function(){const e=qe.chrome,t=e&&e.app&&e.app.runtime,n="history"in qe&&!!qe.history.pushState&&!!qe.history.replaceState;return!t&&n}())return;const e=$e.onpopstate;function t(e){return function(...t){const n=t.length>2?t[2]:void 0;if(n){const e=et,t=String(n);et=t;const i={from:e,to:t};(0,_e.aj)("history",i)}return e.apply(this,t)}}$e.onpopstate=function(...t){const n=$e.location.href,i=et;et=n;const s={from:i,to:n};if((0,_e.aj)("history",s),e)try{return e.apply(this,t)}catch(e){}},(0,we.GS)($e.history,"pushState",t),(0,we.GS)($e.history,"replaceState",t)}const nt="BrowserTracing",it={...i.Cq,markBackgroundTransactions:!0,routingInstrumentation:function(e,t=!0,n=!0){if(!y||!y.location)return void(h&&c.vF.warn("Could not initialize routing instrumentation due to invalid location"));let i,s=y.location.href;t&&(i=e({name:y.location.pathname,startTimestamp:be.k3?be.k3/1e3:void 0,op:"pageload",origin:"auto.pageload.browser",metadata:{source:"url"}})),n&&function(t){const n="history";(0,_e.s5)(n,(({to:t,from:n})=>{void 0===n&&s&&-1!==s.indexOf(t)?s=void 0:n!==t&&(s=void 0,i&&(h&&c.vF.log(`[Tracing] Finishing current transaction with op: ${i.op}`),i.end()),i=e({name:y.location.pathname,op:"navigation",origin:"auto.navigation.browser",metadata:{source:"url"}}))})),(0,_e.AS)(n,tt)}()},startTransactionOnLocationChange:!0,startTransactionOnPageLoad:!0,enableLongTask:!0,enableInp:!1,interactionsSampleRate:1,_experiments:{},...je};function st(e){const t=(n=`meta[name=${e}]`,u.document&&u.document.querySelector?u.document.querySelector(n):null);var n;return t?t.getAttribute("content"):void 0}function ot(e){const t=e.attributes&&e.attributes[r.i_],n=e.data&&e.data[r.i_],i=e.metadata&&e.metadata.source;return t||n||i}var rt=n(2581),at=n(9049);function ct(e){let t,n=e[0],i=1;for(;in.call(t,...e))),t=void 0)}return n}var lt=n(8560),gt=n(4902);function dt(e){const t=ct([e,"call",e=>e(),"access",e=>e.getClient,"call",e=>e(),"optionalAccess",e=>e.getOptions,"call",e=>e()]);return"sentry"!==(ct([t,"optionalAccess",e=>e.instrumenter])||"sentry")}class ut{static __initStatic(){this.id="Apollo"}constructor(e={useNestjs:!1}){this.name=ut.id,this._useNest=!!e.useNestjs}loadDependency(){return this._useNest?this._module=this._module||(0,lt.Vw)("@nestjs/graphql"):this._module=this._module||(0,lt.Vw)("apollo-server-core"),this._module}setupOnce(e,t){if(dt(t))h&&c.vF.log("Apollo Integration is skipped because of instrumenter configuration.");else if(this._useNest){const e=this.loadDependency();if(!e)return void(h&&c.vF.error("Apollo-NestJS Integration was unable to require @nestjs/graphql package."));(0,we.GS)(e.GraphQLFactory.prototype,"mergeWithSchema",(function(e){return function(...n){return(0,we.GS)(this.resolversExplorerService,"explore",(function(e){return function(){return bt((0,gt.k9)(e.call(this)),t)}})),e.call(this,...n)}}))}else{const e=this.loadDependency();if(!e)return void(h&&c.vF.error("Apollo Integration was unable to require apollo-server-core package."));(0,we.GS)(e.ApolloServerBase.prototype,"constructSchema",(function(e){return function(){if(!this.config.resolvers)return h&&(this.config.schema?(c.vF.warn("Apollo integration is not able to trace `ApolloServer` instances constructed via `schema` property.If you are using NestJS with Apollo, please use `Sentry.Integrations.Apollo({ useNestjs: true })` instead."),c.vF.warn()):this.config.modules&&c.vF.warn("Apollo integration is not able to trace `ApolloServer` instances constructed via `modules` property."),c.vF.error("Skipping tracing as no resolvers found on the `ApolloServer` instance.")),e.call(this);const n=(0,gt.k9)(this.config.resolvers);return this.config.resolvers=bt(n,t),e.call(this)}}))}}}function bt(e,t){return e.map((e=>(Object.keys(e).forEach((n=>{Object.keys(e[n]).forEach((i=>{"function"==typeof e[n][i]&&function(e,t,n,i){(0,we.GS)(e[t],n,(function(e){return function(...s){const o=ct([i().getScope().getSpan(),"optionalAccess",e=>e.startChild,"call",e=>e({description:`${t}.${n}`,op:"graphql.resolve",origin:"auto.graphql.apollo"})]),r=e.call(this,...s);return(0,g.Qg)(r)?r.then((e=>(ct([o,"optionalAccess",e=>e.end,"call",e=>e()]),e))):(ct([o,"optionalAccess",e=>e.end,"call",e=>e()]),r)}}))}(e,n,i,t)}))})),e)))}ut.__initStatic();class It{static __initStatic(){this.id="Express"}constructor(e={}){this.name=It.id,this._router=e.router||e.app,this._methods=(Array.isArray(e.methods)?e.methods:[]).concat("use")}setupOnce(e,t){this._router?dt(t)?h&&c.vF.log("Express Integration is skipped because of instrumenter configuration."):(function(e,t=[]){t.forEach((t=>function(e,t){const n=e[t];return e[t]=function(...e){return n.call(this,...function(e,t){return e.map((e=>"function"==typeof e?pt(e,t):Array.isArray(e)?e.map((e=>"function"==typeof e?pt(e,t):e)):e))}(e,t))},e}(e,t)))}(this._router,this._methods),function(e){const t="settings"in e;t&&void 0===e._router&&e.lazyrouter&&e.lazyrouter();const n=t?e._router:e;if(!n)return h&&c.vF.debug("Cannot instrument router for URL Parameterization (did not find a valid router)."),void(h&&c.vF.debug("Routing instrumentation is currently only supported in Express 4."));const i=Object.getPrototypeOf(n),s=i.process_params;i.process_params=function(e,t,n,i,o){n._reconstructedRoute||(n._reconstructedRoute="");const{layerRoutePath:a,isRegex:c,isArray:l,numExtraSegments:u}=function(e){let t=ct([e,"access",e=>e.route,"optionalAccess",e=>e.path]);const n=(0,g.gd)(t),i=Array.isArray(t);if(!t){const[n]=d.OW.process.versions.node.split(".").map(Number);n>=16&&(t=Ct(e.path,e.regexp,e.keys))}if(!t)return{isRegex:n,isArray:i,numExtraSegments:0};const s=i?Math.max(t.reduce(((e,t)=>e+Ce(t.toString())),0)-Ce(e.path||""),0):0,o=function(e,t){return e?t.map((e=>e.toString())).join(","):t&&t.toString()}(i,t);return{layerRoutePath:o,isRegex:n,isArray:i,numExtraSegments:s}}(e);let b;(a||c||l)&&(n._hasParameters=!0),b=a||function(e,t,n){const i=ct([pe(e||""),"optionalAccess",e=>e.split,"call",e=>e("/"),"access",e=>e.filter,"call",e=>e((e=>!!e))]);let s=0;const o=ct([t,"optionalAccess",e=>e.split,"call",e=>e("/"),"access",e=>e.filter,"call",e=>e((e=>!!e)),"access",e=>e.length])||0;return ct([n,"optionalAccess",e=>e.split,"call",e=>e("/"),"access",e=>e.filter,"call",e=>e((e=>ct([i,"optionalAccess",e=>e[o+s]])===e&&(s+=1,!0))),"access",e=>e.join,"call",e=>e("/")])}(n.originalUrl,n._reconstructedRoute,e.path)||"";const I=b.split("/").filter((e=>e.length>0&&(c||l||!e.includes("*")))).join("/");if(I&&I.length>0&&(n._reconstructedRoute+=`/${I}${c?"/":""}`),Ce(pe(n.originalUrl||""))+u===Ce(n._reconstructedRoute)){n._hasParameters||n._reconstructedRoute!==n.originalUrl&&(n._reconstructedRoute=n.originalUrl?pe(n.originalUrl):n.originalUrl);const e=i.__sentry_transaction,t=e&&(0,m.et)(e).data||{};if(e&&"custom"!==t[r.i_]){const t=n._reconstructedRoute||"/",[i,s]=function(e,t={}){const n=e.method&&e.method.toUpperCase();let i="",s="url";t.customRoute||e.route?(i=t.customRoute||`${e.baseUrl||""}${e.route&&e.route.path}`,s="route"):(e.originalUrl||e.url)&&(i=pe(e.originalUrl||e.url||""));let o="";return t.method&&n&&(o+=n),t.method&&t.path&&(o+=" "),t.path&&i&&(o+=i),[o,s]}(n,{path:!0,method:!0,customRoute:t});e.updateName(i),e.setAttribute(r.i_,s)}}return s.call(this,e,t,n,i,o)}}(this._router)):h&&c.vF.error("ExpressIntegration is missing an Express instance")}}function pt(e,t){const n=e.length;switch(n){case 2:return function(n,i){const s=i.__sentry_transaction;if(s){const n=s.startChild({description:e.name,op:`middleware.express.${t}`,origin:"auto.middleware.express"});i.once("finish",(()=>{n.end()}))}return e.call(this,n,i)};case 3:return function(n,i,s){const o=ct([i.__sentry_transaction,"optionalAccess",e=>e.startChild,"call",n=>n({description:e.name,op:`middleware.express.${t}`,origin:"auto.middleware.express"})]);e.call(this,n,i,(function(...e){ct([o,"optionalAccess",e=>e.end,"call",e=>e()]),s.call(this,...e)}))};case 4:return function(n,i,s,o){const r=ct([s.__sentry_transaction,"optionalAccess",e=>e.startChild,"call",n=>n({description:e.name,op:`middleware.express.${t}`,origin:"auto.middleware.express"})]);e.call(this,n,i,s,(function(...e){ct([r,"optionalAccess",e=>e.end,"call",e=>e()]),o.call(this,...e)}))};default:throw new Error(`Express middleware takes 2-4 arguments. Got: ${n}`)}}It.__initStatic();const Ct=(e,t,n)=>{if(!(e&&t&&n&&0!==Object.keys(n).length&&ct([n,"access",e=>e[0],"optionalAccess",e=>e.offset])))return;const i=n.sort(((e,t)=>e.offset-t.offset)),s=new RegExp(t,`${t.flags}d`).exec(e);if(!s||!s.indices)return;const[,...o]=s.indices;if(o.length!==i.length)return;let r=e,a=0;return o.forEach(((e,t)=>{if(e){const[n,s]=e,o=r.substring(0,n-a),c=`:${i[t].name}`,l=r.substring(s-a);r=o+c+l,a+=s-n-c.length}})),r};class ht{static __initStatic(){this.id="GraphQL"}constructor(){this.name=ht.id}loadDependency(){return this._module=this._module||(0,lt.Vw)("graphql/execution/execute.js")}setupOnce(e,t){if(dt(t))return void(h&&c.vF.log("GraphQL Integration is skipped because of instrumenter configuration."));const n=this.loadDependency();n?(0,we.GS)(n,"execute",(function(e){return function(...n){const i=t().getScope(),s=i.getSpan(),o=ct([s,"optionalAccess",e=>e.startChild,"call",e=>e({description:"execute",op:"graphql.execute",origin:"auto.graphql.graphql"})]);ct([i,"optionalAccess",e=>e.setSpan,"call",e=>e(o)]);const r=e.call(this,...n);return(0,g.Qg)(r)?r.then((e=>(ct([o,"optionalAccess",e=>e.end,"call",e=>e()]),ct([i,"optionalAccess",e=>e.setSpan,"call",e=>e(s)]),e))):(ct([o,"optionalAccess",e=>e.end,"call",e=>e()]),ct([i,"optionalAccess",e=>e.setSpan,"call",e=>e(s)]),r)}})):h&&c.vF.error("GraphQL Integration was unable to require graphql/execution package.")}}ht.__initStatic();const mt=["aggregate","bulkWrite","countDocuments","createIndex","createIndexes","deleteMany","deleteOne","distinct","drop","dropIndex","dropIndexes","estimatedDocumentCount","find","findOne","findOneAndDelete","findOneAndReplace","findOneAndUpdate","indexes","indexExists","indexInformation","initializeOrderedBulkOp","insertMany","insertOne","isCapped","mapReduce","options","parallelCollectionScan","rename","replaceOne","stats","updateMany","updateOne"],yt={bulkWrite:["operations"],countDocuments:["query"],createIndex:["fieldOrSpec"],createIndexes:["indexSpecs"],deleteMany:["filter"],deleteOne:["filter"],distinct:["key","query"],dropIndex:["indexName"],find:["query"],findOne:["query"],findOneAndDelete:["filter"],findOneAndReplace:["filter","replacement"],findOneAndUpdate:["filter","update"],indexExists:["indexes"],insertMany:["docs"],insertOne:["doc"],mapReduce:["map","reduce"],rename:["newName"],replaceOne:["filter","doc"],updateMany:["filter","update"],updateOne:["filter","update"]};class Zt{static __initStatic(){this.id="Mongo"}constructor(e={}){this.name=Zt.id,this._operations=Array.isArray(e.operations)?e.operations:mt,this._describeOperations=!("describeOperations"in e)||e.describeOperations,this._useMongoose=!!e.useMongoose}loadDependency(){const e=this._useMongoose?"mongoose":"mongodb";return this._module=this._module||(0,lt.Vw)(e)}setupOnce(e,t){if(dt(t))return void(h&&c.vF.log("Mongo Integration is skipped because of instrumenter configuration."));const n=this.loadDependency();if(n)this._instrumentOperations(n.Collection,this._operations,t);else{const e=this._useMongoose?"mongoose":"mongodb";h&&c.vF.error(`Mongo Integration was unable to require \`${e}\` package.`)}}_instrumentOperations(e,t,n){t.forEach((t=>this._patchOperation(e,t,n)))}_patchOperation(e,t,n){if(!(t in e.prototype))return;const i=this._getSpanContextFromOperationArguments.bind(this);(0,we.GS)(e.prototype,t,(function(e){return function(...s){const o=s[s.length-1],r=n(),a=r.getScope(),c=r.getClient(),l=a.getSpan(),d=ct([c,"optionalAccess",e=>e.getOptions,"call",e=>e(),"access",e=>e.sendDefaultPii]);if("function"!=typeof o||"mapReduce"===t&&2===s.length){const n=ct([l,"optionalAccess",e=>e.startChild,"call",e=>e(i(this,t,s,d))]),o=e.call(this,...s);if((0,g.Qg)(o))return o.then((e=>(ct([n,"optionalAccess",e=>e.end,"call",e=>e()]),e)));if((u=o)&&"object"==typeof u&&u.once&&"function"==typeof u.once){const e=o;try{e.once("close",(()=>{ct([n,"optionalAccess",e=>e.end,"call",e=>e()])}))}catch(e){ct([n,"optionalAccess",e=>e.end,"call",e=>e()])}return e}return ct([n,"optionalAccess",e=>e.end,"call",e=>e()]),o}var u;const b=ct([l,"optionalAccess",e=>e.startChild,"call",e=>e(i(this,t,s.slice(0,-1)))]);return e.call(this,...s.slice(0,-1),(function(e,t){ct([b,"optionalAccess",e=>e.end,"call",e=>e()]),o(e,t)}))}}))}_getSpanContextFromOperationArguments(e,t,n,i=!1){const s={"db.system":"mongodb","db.name":e.dbName,"db.operation":t,"db.mongodb.collection":e.collectionName},o={op:"db",origin:"auto.db.mongo",description:t,data:s},r=yt[t],a=Array.isArray(this._describeOperations)?this._describeOperations.includes(t):this._describeOperations;if(!r||!a||!i)return o;try{if("mapReduce"===t){const[e,t]=n;s[r[0]]="string"==typeof e?e:e.name||"",s[r[1]]="string"==typeof t?t:t.name||""}else for(let e=0;e(i||(i=t.config),e.apply(t,n))})}catch(e){h&&c.vF.error("Mysql Integration was unable to instrument `mysql` config.")}function s(e){if(!e)return;const t=i?{"server.address":i.host,"server.port":i.port,"db.user":i.user}:{};Object.keys(t).forEach((n=>{e.setAttribute(n,t[n])})),e.end()}(0,we.GS)(n,"createQuery",(function(e){return function(n,i,o){const r=ct([t().getScope().getSpan(),"optionalAccess",e=>e.startChild,"call",e=>e({description:"string"==typeof n?n:n.sql,op:"db",origin:"auto.db.mysql",data:{"db.system":"mysql"}})]);if("function"==typeof o)return e.call(this,n,i,(function(e,t,n){s(r),o(e,t,n)}));if("function"==typeof i)return e.call(this,n,(function(e,t,n){s(r),i(e,t,n)}));const a=e.call(this,n,i);return a.on("end",(()=>{s(r)})),a}}))}}Gt.__initStatic();class Bt{static __initStatic(){this.id="Postgres"}constructor(e={}){this.name=Bt.id,this._usePgNative=!!e.usePgNative,this._module=e.module}loadDependency(){return this._module=this._module||(0,lt.Vw)("pg")}setupOnce(e,t){if(dt(t))return void(h&&c.vF.log("Postgres Integration is skipped because of instrumenter configuration."));const n=this.loadDependency();if(!n)return void(h&&c.vF.error("Postgres Integration was unable to require `pg` package."));const i=this._usePgNative?ct([n,"access",e=>e.native,"optionalAccess",e=>e.Client]):n.Client;i?(0,we.GS)(i.prototype,"query",(function(e){return function(n,i,s){const o=t().getScope().getSpan(),r={"db.system":"postgresql"};try{this.database&&(r["db.name"]=this.database),this.host&&(r["server.address"]=this.host),this.port&&(r["server.port"]=this.port),this.user&&(r["db.user"]=this.user)}catch(e){}const a=ct([o,"optionalAccess",e=>e.startChild,"call",e=>e({description:"string"==typeof n?n:n.text,op:"db",origin:"auto.db.postgres",data:r})]);if("function"==typeof s)return e.call(this,n,i,(function(e,t){ct([a,"optionalAccess",e=>e.end,"call",e=>e()]),s(e,t)}));if("function"==typeof i)return e.call(this,n,(function(e,t){ct([a,"optionalAccess",e=>e.end,"call",e=>e()]),i(e,t)}));const c=void 0!==i?e.call(this,n,i):e.call(this,n);return(0,g.Qg)(c)?c.then((e=>(ct([a,"optionalAccess",e=>e.end,"call",e=>e()]),e))):(ct([a,"optionalAccess",e=>e.end,"call",e=>e()]),c)}})):h&&c.vF.error("Postgres Integration was unable to access 'pg-native' bindings.")}}Bt.__initStatic();class At{static __initStatic(){this.id="Prisma"}constructor(e={}){if(this.name=At.id,(t=e.client)&&t.$use&&!e.client._sentryInstrumented){(0,we.my)(e.client,"_sentryInstrumented",!0);const t={};try{const n=e.client._engineConfig;if(n){const{activeProvider:e,clientVersion:i}=n;e&&(t["db.system"]=e),i&&(t["db.prisma.version"]=i)}}catch(e){}e.client.$use(((e,n)=>{if(dt(He.BF))return n(e);const i=e.action,s=e.model;return(0,Se.Lk)({name:s?`${s} ${i}`:i,onlyIfParent:!0,op:"db.prisma",attributes:{[r.JD]:"auto.db.prisma"},data:{...t,"db.operation":i}},(()=>n(e)))}))}else h&&c.vF.warn("Unsupported Prisma client provided to PrismaIntegration. Provided client:",e.client);var t}setupOnce(){}}At.__initStatic();const Wt=class{constructor(e){this.name=nt,this._hasSetTracePropagationTargets=!1,(0,s.U)(),h&&(this._hasSetTracePropagationTargets=!(!e||!e.tracePropagationTargets&&!e.tracingOrigins)),this.options={...it,...e},void 0!==this.options._experiments.enableLongTask&&(this.options.enableLongTask=this.options._experiments.enableLongTask),e&&!e.tracePropagationTargets&&e.tracingOrigins&&(this.options.tracePropagationTargets=e.tracingOrigins),this._collectWebVitals=Ve(),this._interactionIdToRouteNameMapping={},this.options.enableInp&&function(e,t){if(Ge()&&be.k3){const n=function(e,t){return n=({metric:n})=>{if(void 0===n.value)return;const i=n.entries.find((e=>e.duration===n.value&&void 0!==ve[e.name])),s=(0,a.KU)();if(!i||!s)return;const o=ve[i.name],r=s.getOptions(),l=Ze(be.k3+i.startTime),g=Ze(n.value),d=void 0!==i.interactionId?e[i.interactionId]:void 0;if(void 0===d)return;const{routeName:u,parentContext:b,activeTransaction:p,user:C,replayId:m}=d,Z=void 0!==C?C.email||C.id||C.ip_address:void 0,G=void 0!==p?p.getProfileId():void 0,B=new le.L({startTimestamp:l,endTimestamp:l+g,op:`ui.interaction.${o}`,name:I(i.target),attributes:{release:r.release,environment:r.environment,transaction:u,...void 0!==Z&&""!==Z?{user:Z}:{},...void 0!==G?{profile_id:G}:{},...void 0!==m?{replay_id:m}:{}},exclusiveTime:n.value,measurements:{inp:{value:n.value,unit:"millisecond"}}}),A=function(e,t,n){if(!(0,de.w)(t))return!1;let i;return i=void 0!==e&&"function"==typeof t.tracesSampler?t.tracesSampler({transactionContext:e,name:e.name,parentSampled:e.parentSampled,attributes:{...e.data,...e.attributes},location:y.location}):void 0!==e&&void 0!==e.sampled?e.sampled:void 0!==t.tracesSampleRate?t.tracesSampleRate:1,(0,ue.v)(i)?!0===i?n:!1===i?0:i*n:(h&&c.vF.warn("[Tracing] Discarding interaction span because of invalid sample rate."),!1)}(b,r,t);if(A&&Math.random(){h&&c.vF.error("Error while sending interaction:",e)}))}},re("inp",n,oe,q);var n}(e,t);return()=>{n()}}}(this._interactionIdToRouteNameMapping,this.options.interactionsSampleRate),this.options.enableLongTask&&$("longtask",(({entries:e})=>{for(const t of e){const e=(0,o.Z7)();if(!e)return;const n=Ze(be.k3+t.startTime),i=Ze(t.duration);e.startChild({description:"Main UI thread blocked",op:"ui.long-task",origin:"auto.ui.browser.metrics",startTimestamp:n,endTimestamp:n+i})}})),this.options._experiments.enableInteractions&&$("event",(({entries:e})=>{for(const t of e){const e=(0,o.Z7)();if(!e)return;if("click"===t.name){const n=Ze(be.k3+t.startTime),i=Ze(t.duration),s={description:I(t.target),op:`ui.interaction.${t.name}`,origin:"auto.ui.browser.metrics",startTimestamp:n,endTimestamp:n+i},o=C(t.target);o&&(s.attributes={"ui.component_name":o}),e.startChild(s)}}})),this._latestRoute={name:void 0,context:void 0}}setupOnce(e,t){this._getCurrentHub=t;const n=t().getClient(),i=n&&n.getOptions(),{routingInstrumentation:s,startTransactionOnLocationChange:r,startTransactionOnPageLoad:a,markBackgroundTransactions:l,traceFetch:g,traceXHR:d,shouldCreateSpanForRequest:u,enableHTTPTimings:b,_experiments:I}=this.options,p=i&&i.tracePropagationTargets,C=p||this.options.tracePropagationTargets;h&&this._hasSetTracePropagationTargets&&p&&c.vF.warn("[Tracing] The `tracePropagationTargets` option was set in the BrowserTracing integration and top level `Sentry.init`. The top level `Sentry.init` value is being used."),s((e=>{const n=this._createRouteTransaction(e);return this.options._experiments.onStartRouteTransaction&&this.options._experiments.onStartRouteTransaction(n,e,t),n}),a,r),l&&(y.document?y.document.addEventListener("visibilitychange",(()=>{const e=(0,o.Z7)();if(y.document.hidden&&e){const t="cancelled",{op:n,status:i}=(0,m.et)(e);h&&c.vF.log(`[Tracing] Transaction: ${t} -> since tab moved to the background, op: ${n}`),i||e.setStatus(t),e.setTag("visibilitychange","document.hidden"),e.end()}})):h&&c.vF.warn("[Tracing] Could not set up background tab detection due to lack of global document")),I.enableInteractions&&this._registerInteractionListener(),this.options.enableInp&&this._registerInpInteractionListener(),Oe({traceFetch:g,traceXHR:d,tracePropagationTargets:C,shouldCreateSpanForRequest:u,enableHTTPTimings:b})}_createRouteTransaction(e){if(!this._getCurrentHub)return void(h&&c.vF.warn(`[Tracing] Did not create ${e.op} transaction because _getCurrentHub is invalid.`));const t=this._getCurrentHub(),{beforeNavigate:n,idleTimeout:i,finalTimeout:r,heartbeatInterval:a}=this.options,g="pageload"===e.op;let d;if(g){const t=g?st("sentry-trace"):"",n=g?st("baggage"):void 0,{traceId:i,dsc:s,parentSpanId:o,sampled:r}=(0,l.kM)(t,n);d={traceId:i,parentSpanId:o,parentSampled:r,...e,metadata:{...e.metadata,dynamicSamplingContext:s},trimEnd:!0}}else d={trimEnd:!0,...e};const u="function"==typeof n?n(d):d,b=void 0===u?{...d,sampled:!1}:u;b.metadata=b.name!==d.name?{...b.metadata,source:"custom"}:b.metadata,this._latestRoute.name=b.name,this._latestRoute.context=b,!1===b.sampled&&h&&c.vF.log(`[Tracing] Will not send ${b.op} transaction because of beforeNavigate.`),h&&c.vF.log(`[Tracing] Starting ${b.op} transaction on scope`);const{location:p}=y,C=(0,s.p)(t,b,i,r,!0,{location:p},a,g);return g&&y.document&&(y.document.addEventListener("readystatechange",(()=>{["interactive","complete"].includes(y.document.readyState)&&C.sendAutoFinishSignal()})),["interactive","complete"].includes(y.document.readyState)&&C.sendAutoFinishSignal()),C.registerBeforeFinishCallback((e=>{this._collectWebVitals(),function(e){const t=Ge();if(!t||!y.performance.getEntries||!be.k3)return;h&&c.vF.log("[Tracing] Adding & adjusting spans using Performance API");const n=Ze(be.k3),i=t.getEntries(),{op:s,start_timestamp:r}=(0,m.et)(e);if(i.slice(We).forEach((t=>{const i=Ze(t.startTime),s=Ze(t.duration);if(!("navigation"===e.op&&r&&n+i{Re(e,t,i,n)})),Re(e,t,"secureConnection",n,"TLS/SSL","connectEnd"),Re(e,t,"fetch",n,"cache","domainLookupStart"),Re(e,t,"domainLookup",n,"DNS"),function(e,t,n){t.responseEnd&&(me(e,{op:"browser",origin:"auto.browser.browser.metrics",description:"request",startTimestamp:n+Ze(t.requestStart),endTimestamp:n+Ze(t.responseEnd)}),me(e,{op:"browser",origin:"auto.browser.browser.metrics",description:"response",startTimestamp:n+Ze(t.responseStart),endTimestamp:n+Ze(t.responseEnd)}))}(e,t,n)}(e,t,n);break;case"mark":case"paint":case"measure":{!function(e,t,n,i,s){const o=s+n,r=o+i;me(e,{description:t.name,endTimestamp:r,op:t.entryType,origin:"auto.resource.browser.metrics",startTimestamp:o})}(e,t,i,s,n);const o=Y(),r=t.startTime{if(!fe[e]||!r||n>=r)return;const t=fe[e].value,i=n+Ze(t),s=Math.abs(1e3*(i-r)),o=s-t;h&&c.vF.log(`[Measurements] Normalized ${e} from ${t} to ${s} (${o})`),fe[e].value=s}));const t=fe["mark.fid"];t&&fe.fid&&(me(e,{description:"first input delay",endTimestamp:t.value+Ze(fe.fid.value),op:"ui.action",origin:"auto.ui.browser.metrics",startTimestamp:t.value}),delete fe["mark.fid"]),"fcp"in fe||delete fe.cls,Object.keys(fe).forEach((e=>{!function(e,t,n){const i=(0,o.Z7)();i&&i.setMeasurement(e,t,n)}(e,fe[e].value,fe[e].unit)})),function(e){Be&&(h&&c.vF.log("[Measurements] Adding LCP Data"),Be.element&&e.setTag("lcp.element",I(Be.element)),Be.id&&e.setTag("lcp.id",Be.id),Be.url&&e.setTag("lcp.url",Be.url.trim().slice(0,200)),e.setTag("lcp.size",Be.size)),Ae&&Ae.sources&&(h&&c.vF.log("[Measurements] Adding CLS Data"),Ae.sources.forEach(((t,n)=>e.setTag(`cls.source.${n+1}`,I(t.node)))))}(e)}Be=void 0,Ae=void 0,fe={}}(e)})),C}_registerInteractionListener(){let e;const t=()=>{const{idleTimeout:t,finalTimeout:n,heartbeatInterval:i}=this.options,a="ui.action.click",l=(0,o.Z7)();if(l&&l.op&&["navigation","pageload"].includes(l.op))return void(h&&c.vF.warn(`[Tracing] Did not create ${a} transaction because a pageload or navigation transaction is in progress.`));if(e&&(e.setFinishReason("interactionInterrupted"),e.end(),e=void 0),!this._getCurrentHub)return void(h&&c.vF.warn(`[Tracing] Did not create ${a} transaction because _getCurrentHub is invalid.`));if(!this._latestRoute.name)return void(h&&c.vF.warn(`[Tracing] Did not create ${a} transaction because _latestRouteName is missing.`));const g=this._getCurrentHub(),{location:d}=y,u={name:this._latestRoute.name,op:a,trimEnd:!0,data:{[r.i_]:this._latestRoute.context?ot(this._latestRoute.context):"url"}};e=(0,s.p)(g,u,t,n,!0,{location:d},i)};["click"].forEach((e=>{y.document&&addEventListener(e,t,{once:!1,capture:!0})}))}_registerInpInteractionListener(){const e=({entries:e})=>{const t=(0,a.KU)(),n=void 0!==t&&void 0!==t.getIntegrationByName?t.getIntegrationByName("Replay"):void 0,i=void 0!==n?n.getReplayId():void 0,s=(0,o.Z7)(),r=(0,a.o5)(),c=void 0!==r?r.getUser():void 0;e.forEach((e=>{if(function(e){return"duration"in e}(e)){const t=e.interactionId;if(void 0===t)return;const n=this._interactionIdToRouteNameMapping[t],o=e.duration,r=e.startTime,a=Object.keys(this._interactionIdToRouteNameMapping),l=a.length>0?a.reduce(((e,t)=>this._interactionIdToRouteNameMapping[e].durationthis._interactionIdToRouteNameMapping[e])).some((e=>e.duration===o&&e.startTime===r)))return;if(!t)return;if(n)n.duration=Math.max(n.duration,o);else if(a.length<10||void 0===l||o>this._interactionIdToRouteNameMapping[l].duration){const e=this._latestRoute.name,n=this._latestRoute.context;e&&n&&(l&&Object.keys(this._interactionIdToRouteNameMapping).length>=10&&delete this._interactionIdToRouteNameMapping[l],this._interactionIdToRouteNameMapping[t]={routeName:e,duration:o,parentContext:n,user:c,activeTransaction:s,replayId:i,startTime:r})}}}))};$("event",e),$("first-input",e)}},ft=rt.l,Vt=o.Z7,vt=o.nc,Rt=Xe.o6,Yt=at.Z,Xt=le.L,Ht=nt,St=je,Nt=de.w,wt=pe,Kt=l.MI,Ft=i.zX,kt=Oe,_t=s.p,Jt=Xe.Fp,zt={BrowserTracing:Wt,Apollo:ut,Express:It,GraphQL:ht,Mongo:Zt,Mysql:Gt,Postgres:Bt,Prisma:At};("undefined"==typeof __SENTRY_TRACING__||__SENTRY_TRACING__)&&(0,rt.l)()},5584:(e,t,n)=>{"use strict";n.d(t,{De:()=>g,yD:()=>l});var i=n(5644),s=n(3816),o=n(7412);const r="sentry-",a=/^sentry-/,c=8192;function l(e){if(!(0,s.Kg)(e)&&!Array.isArray(e))return;let t={};if(Array.isArray(e))t=e.reduce(((e,t)=>{const n=d(t);for(const t of Object.keys(n))e[t]=n[t];return e}),{});else{if(!e)return;t=d(e)}const n=Object.entries(t).reduce(((e,[t,n])=>(t.match(a)&&(e[t.slice(r.length)]=n),e)),{});return Object.keys(n).length>0?n:void 0}function g(e){if(e)return function(e){if(0!==Object.keys(e).length)return Object.entries(e).reduce(((e,[t,n],s)=>{const r=`${encodeURIComponent(t)}=${encodeURIComponent(n)}`,a=0===s?r:`${e},${r}`;return a.length>c?(i.T&&o.vF.warn(`Not adding key: ${t} with val: ${n} to baggage header due to exceeding baggage size limits.`),e):a}),"")}(Object.entries(e).reduce(((e,[t,n])=>(n&&(e[`${r}${t}`]=n),e)),{}))}function d(e){return e.split(",").map((e=>e.split("=").map((e=>decodeURIComponent(e.trim()))))).reduce(((e,[t,n])=>(e[t]=n,e)),{})}},853:(e,t,n)=>{"use strict";function i(e){let t,n=e[0],i=1;for(;in.call(t,...e))),t=void 0)}return n}n.d(t,{z:()=>i})},5644:(e,t,n)=>{"use strict";n.d(t,{T:()=>i});const i="undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__},3816:(e,t,n)=>{"use strict";n.d(t,{Kg:()=>r,L2:()=>h,NF:()=>a,Qd:()=>l,Qg:()=>b,bJ:()=>s,gd:()=>u,mE:()=>I,sO:()=>c,tH:()=>C,vq:()=>d,xH:()=>g,yr:()=>p});const i=Object.prototype.toString;function s(e){switch(i.call(e)){case"[object Error]":case"[object Exception]":case"[object DOMException]":return!0;default:return C(e,Error)}}function o(e,t){return i.call(e)===`[object ${t}]`}function r(e){return o(e,"String")}function a(e){return"object"==typeof e&&null!==e&&"__sentry_template_string__"in e&&"__sentry_template_values__"in e}function c(e){return null===e||a(e)||"object"!=typeof e&&"function"!=typeof e}function l(e){return o(e,"Object")}function g(e){return"undefined"!=typeof Event&&C(e,Event)}function d(e){return"undefined"!=typeof Element&&C(e,Element)}function u(e){return o(e,"RegExp")}function b(e){return Boolean(e&&e.then&&"function"==typeof e.then)}function I(e){return l(e)&&"nativeEvent"in e&&"preventDefault"in e&&"stopPropagation"in e}function p(e){return"number"==typeof e&&e!=e}function C(e,t){try{return e instanceof t}catch(e){return!1}}function h(e){return!("object"!=typeof e||null===e||!e.__isVue&&!e._isVue)}},7412:(e,t,n)=>{"use strict";n.d(t,{Ow:()=>o,Z9:()=>r,pq:()=>a,vF:()=>c});var i=n(5644),s=n(6341);const o=["debug","info","warn","error","log","assert","trace"],r={};function a(e){if(!("console"in s.OW))return e();const t=s.OW.console,n={},i=Object.keys(r);i.forEach((e=>{const i=r[e];n[e]=t[e],t[e]=i}));try{return e()}finally{i.forEach((e=>{t[e]=n[e]}))}}const c=function(){let e=!1;const t={enable:()=>{e=!0},disable:()=>{e=!1},isEnabled:()=>e};return i.T?o.forEach((n=>{t[n]=(...t)=>{e&&a((()=>{s.OW.console[n](`Sentry Logger [${n}]:`,...t)}))}})):o.forEach((e=>{t[e]=()=>{}})),t}()},6936:(e,t,n)=>{"use strict";n.d(t,{$X:()=>c,GR:()=>I,M6:()=>g,db:()=>b,eJ:()=>r,gO:()=>l,k9:()=>p,kf:()=>u});var i=n(4022),s=n(9653),o=n(6341);function r(){const e=o.OW,t=e.crypto||e.msCrypto;let n=()=>16*Math.random();try{if(t&&t.randomUUID)return t.randomUUID().replace(/-/g,"");t&&t.getRandomValues&&(n=()=>{const e=new Uint8Array(1);return t.getRandomValues(e),e[0]})}catch(e){}return([1e7]+1e3+4e3+8e3+1e11).replace(/[018]/g,(e=>(e^(15&n())>>e/4).toString(16)))}function a(e){return e.exception&&e.exception.values?e.exception.values[0]:void 0}function c(e){const{message:t,event_id:n}=e;if(t)return t;const i=a(e);return i?i.type&&i.value?`${i.type}: ${i.value}`:i.type||i.value||n||"":n||""}function l(e,t,n){const i=e.exception=e.exception||{},s=i.values=i.values||[],o=s[0]=s[0]||{};o.value||(o.value=t||""),o.type||(o.type=n||"Error")}function g(e,t){const n=a(e);if(!n)return;const i=n.mechanism;if(n.mechanism={type:"generic",handled:!0,...i,...t},t&&"data"in t){const e={...i&&i.data,...t.data};n.mechanism.data=e}}const d=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;function u(e){const t=e.match(d)||[],n=parseInt(t[1],10),i=parseInt(t[2],10),s=parseInt(t[3],10);return{buildmetadata:t[5],major:isNaN(n)?void 0:n,minor:isNaN(i)?void 0:i,patch:isNaN(s)?void 0:s,prerelease:t[4]}}function b(e,t,n=5){if(void 0===t.lineno)return;const i=e.length,o=Math.max(Math.min(i-1,t.lineno-1),0);t.pre_context=e.slice(Math.max(0,o-n),o).map((e=>(0,s.nC)(e,0))),t.context_line=(0,s.nC)(e[Math.min(i-1,o)],t.colno||0),t.post_context=e.slice(Math.min(o+1,i),o+1+n).map((e=>(0,s.nC)(e,0)))}function I(e){if(e&&e.__sentry_captured__)return!0;try{(0,i.my)(e,"__sentry_captured__",!0)}catch(e){}return!1}function p(e){return Array.isArray(e)?e:[e]}},3903:(e,t,n)=>{"use strict";function i(e,t){return e.require(t)}function s(t){let n;try{n=i(e,t)}catch(e){}try{const{cwd:s}=i(e,"process");n=i(e,`${s()}/node_modules/${t}`)}catch(e){}return n}n.d(t,{Vw:()=>s,fj:()=>i}),e=n.hmd(e)},2181:(e,t,n)=>{"use strict";n.d(t,{S8:()=>r,cd:()=>a});var i=n(3816),s=n(4022),o=n(7930);function r(e,t=100,n=1/0){try{return c("",e,t,n)}catch(e){return{ERROR:`**non-serializable** (${e})`}}}function a(e,t=3,n=102400){const i=r(e,t);return s=i,function(e){return~-encodeURI(e).split(/%..|./).length}(JSON.stringify(s))>n?a(e,t-1,n):i;var s}function c(e,t,n=1/0,r=1/0,a=function(){const e="function"==typeof WeakSet,t=e?new WeakSet:[];return[function(n){if(e)return!!t.has(n)||(t.add(n),!1);for(let e=0;e=r){I[e]="[MaxProperties ~]";break}const t=C[e];I[e]=c(e,t,u-1,r,a),p++}return g(t),I}},4022:(e,t,n)=>{"use strict";n.d(t,{my:()=>d,W4:()=>I,Ce:()=>m,HF:()=>h,GS:()=>g,sp:()=>u,u4:()=>b});var i=n(3816);const s=(0,n(6341).VZ)(),o=80;function r(e,t){const n=e,o=[];let r,a,c,l,g;if(!n||!n.tagName)return"";if(s.HTMLElement&&n instanceof HTMLElement&&n.dataset&&n.dataset.sentryComponent)return n.dataset.sentryComponent;o.push(n.tagName.toLowerCase());const d=t&&t.length?t.filter((e=>n.getAttribute(e))).map((e=>[e,n.getAttribute(e)])):null;if(d&&d.length)d.forEach((e=>{o.push(`[${e[0]}="${e[1]}"]`)}));else if(n.id&&o.push(`#${n.id}`),r=n.className,r&&(0,i.Kg)(r))for(a=r.split(/\s+/),g=0;g`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`)).join("&")}function I(e){if((0,i.bJ)(e))return{message:e.message,name:e.name,stack:e.stack,...C(e)};if((0,i.xH)(e)){const t={type:e.type,target:p(e.target),currentTarget:p(e.currentTarget),...C(e)};return"undefined"!=typeof CustomEvent&&(0,i.tH)(e,CustomEvent)&&(t.detail=e.detail),t}return e}function p(e){try{return(0,i.vq)(e)?function(e,t={}){if(!e)return"";try{let n=e;const i=5,s=[];let a=0,c=0;const l=" > ",g=l.length;let d;const u=Array.isArray(t)?t:t.keyAttrs,b=!Array.isArray(t)&&t.maxStringLength||o;for(;n&&a++1&&c+s.length*g+d.length>=b));)s.push(d),c+=d.length,n=n.parentNode;return s.reverse().join(l)}catch(e){return""}}(e):Object.prototype.toString.call(e)}catch(e){return""}}function C(e){if("object"==typeof e&&null!==e){const t={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}return{}}function h(e,t=40){const n=Object.keys(I(e));if(n.sort(),!n.length)return"[object has no keys]";if(n[0].length>=t)return(0,l.xv)(n[0],t);for(let e=n.length;e>0;e--){const i=n.slice(0,e).join(", ");if(!(i.length>t))return e===n.length?i:(0,l.xv)(i,t)}return""}function m(e){return y(e,new Map)}function y(e,t){if(function(e){if(!(0,i.Qd)(e))return!1;try{const t=Object.getPrototypeOf(e).constructor.name;return!t||"Object"===t}catch(e){return!0}}(e)){const n=t.get(e);if(void 0!==n)return n;const i={};t.set(e,i);for(const n of Object.keys(e))void 0!==e[n]&&(i[n]=y(e[n],t));return i}if(Array.isArray(e)){const n=t.get(e);if(void 0!==n)return n;const i=[];return t.set(e,i),e.forEach((e=>{i.push(y(e,t))})),i}return e}},7930:(e,t,n)=>{"use strict";function i(e,t=!1){return!(t||e&&!e.startsWith("/")&&!e.match(/^[A-Z]:/)&&!e.startsWith(".")&&!e.match(/^[a-zA-Z]([a-zA-Z0-9.\-+])*:\/\//)||void 0===e||e.includes("node_modules/"))}function s(e){const t=/^\s*[-]{4,}$/,n=/at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/;return s=>{const o=s.match(n);if(o){let t,n,s,r,a;if(o[1]){s=o[1];let e=s.lastIndexOf(".");if("."===s[e-1]&&e--,e>0){t=s.slice(0,e),n=s.slice(e+1);const i=t.indexOf(".Module");i>0&&(s=s.slice(i+1),t=t.slice(0,i))}r=void 0}n&&(r=t,a=n),""===n&&(a=void 0,s=void 0),void 0===s&&(a=a||"",s=r?`${r}.${a}`:a);let c=o[2]&&o[2].startsWith("file://")?o[2].slice(7):o[2];const l="native"===o[5];return c&&c.match(/\/[A-Z]:/)&&(c=c.slice(1)),c||!o[5]||l||(c=o[5]),{filename:c,module:e?e(c):void 0,function:s,lineno:parseInt(o[3],10)||void 0,colno:parseInt(o[4],10)||void 0,in_app:i(c,l)}}if(s.match(t))return{filename:s}}}n.d(t,{gd:()=>c,qQ:()=>d,o:()=>u,vk:()=>l});const o=50,r=/\(error: (.*)\)/,a=/captureMessage|captureException/;function c(...e){const t=e.sort(((e,t)=>e[0]-t[0])).map((e=>e[1]));return(e,n=0)=>{const i=[],s=e.split("\n");for(let e=n;e1024)continue;const a=r.test(n)?n.replace(r,"$1"):n;if(!a.match(/\S*Error: /)){for(const e of t){const t=e(a);if(t){i.push(t);break}}if(i.length>=o)break}}return function(e){if(!e.length)return[];const t=Array.from(e);return/sentryWrapped/.test(t[t.length-1].function||"")&&t.pop(),t.reverse(),a.test(t[t.length-1].function||"")&&(t.pop(),a.test(t[t.length-1].function||"")&&t.pop()),t.slice(0,o).map((e=>({...e,filename:e.filename||t[t.length-1].filename,function:e.function||"?"})))}(i)}}function l(e){return Array.isArray(e)?c(...e):e}const g="";function d(e){try{return e&&"function"==typeof e&&e.name||g}catch(e){return g}}function u(e){return[90,s(e)]}},9653:(e,t,n)=>{"use strict";n.d(t,{Xr:()=>a,gt:()=>r,nC:()=>o,xv:()=>s});var i=n(3816);function s(e,t=0){return"string"!=typeof e||0===t||e.length<=t?e:`${e.slice(0,t)}...`}function o(e,t){let n=e;const i=n.length;if(i<=150)return n;t>i&&(t=i);let s=Math.max(t-60,0);s<5&&(s=0);let o=Math.min(s+140,i);return o>i-5&&(o=i),o===i&&(s=Math.max(o-140,0)),n=n.slice(s,o),s>0&&(n=`'{snip} ${n}`),ofunction(e,t,n=!1){return!!(0,i.Kg)(e)&&((0,i.gd)(t)?t.test(e):!!(0,i.Kg)(t)&&(n?e===t:e.includes(t)))}(e,t,n)))}},690:(e,t,n)=>{"use strict";n.d(t,{T2:()=>a,XW:()=>o,xg:()=>r});var i,s=n(3816);function o(e){return new a((t=>{t(e)}))}function r(e){return new a(((t,n)=>{n(e)}))}!function(e){e[e.PENDING=0]="PENDING",e[e.RESOLVED=1]="RESOLVED",e[e.REJECTED=2]="REJECTED"}(i||(i={}));class a{constructor(e){a.prototype.__init.call(this),a.prototype.__init2.call(this),a.prototype.__init3.call(this),a.prototype.__init4.call(this),this._state=i.PENDING,this._handlers=[];try{e(this._resolve,this._reject)}catch(e){this._reject(e)}}then(e,t){return new a(((n,i)=>{this._handlers.push([!1,t=>{if(e)try{n(e(t))}catch(e){i(e)}else n(t)},e=>{if(t)try{n(t(e))}catch(e){i(e)}else i(e)}]),this._executeHandlers()}))}catch(e){return this.then((e=>e),e)}finally(e){return new a(((t,n)=>{let i,s;return this.then((t=>{s=!1,i=t,e&&e()}),(t=>{s=!0,i=t,e&&e()})).then((()=>{s?n(i):t(i)}))}))}__init(){this._resolve=e=>{this._setResult(i.RESOLVED,e)}}__init2(){this._reject=e=>{this._setResult(i.REJECTED,e)}}__init3(){this._setResult=(e,t)=>{this._state===i.PENDING&&((0,s.Qg)(t)?t.then(this._resolve,this._reject):(this._state=e,this._value=t,this._executeHandlers()))}}__init4(){this._executeHandlers=()=>{if(this._state===i.PENDING)return;const e=this._handlers.slice();this._handlers=[],e.forEach((e=>{e[0]||(this._state===i.RESOLVED&&e[1](this._value),this._state===i.REJECTED&&e[2](this._value),e[0]=!0)}))}}}},9297:(e,t,n)=>{"use strict";n.d(t,{lu:()=>o,zf:()=>r});var i=n(6341);const s=1e3;function o(){return Date.now()/s}const r=function(){const{performance:e}=i.OW;if(!e||!e.now)return o;const t=Date.now()-e.now(),n=null==e.timeOrigin?t:e.timeOrigin;return()=>(n+e.now())/s}();let a;(()=>{const{performance:e}=i.OW;if(!e||!e.now)return void(a="none");const t=36e5,n=e.now(),s=Date.now(),o=e.timeOrigin?Math.abs(e.timeOrigin+n-s):t,r=o{"use strict";n.d(t,{E0:()=>a,TC:()=>l,kM:()=>c,nc:()=>r});var i=n(5584),s=n(6936);const o=new RegExp("^[ \\t]*([0-9a-f]{32})?-?([0-9a-f]{16})?-?([01])?[ \\t]*$");function r(e){if(!e)return;const t=e.match(o);if(!t)return;let n;return"1"===t[3]?n=!0:"0"===t[3]&&(n=!1),{traceId:t[1],parentSampled:n,parentSpanId:t[2]}}function a(e,t){const n=r(e),o=(0,i.yD)(t),{traceId:a,parentSpanId:c,parentSampled:l}=n||{};return n?{traceparentData:n,dynamicSamplingContext:o||{},propagationContext:{traceId:a||(0,s.eJ)(),parentSpanId:c||(0,s.eJ)().substring(16),spanId:(0,s.eJ)().substring(16),sampled:l,dsc:o||{}}}:{traceparentData:n,dynamicSamplingContext:void 0,propagationContext:{traceId:a||(0,s.eJ)(),spanId:(0,s.eJ)().substring(16)}}}function c(e,t){const n=r(e),o=(0,i.yD)(t),{traceId:a,parentSpanId:c,parentSampled:l}=n||{};return n?{traceId:a||(0,s.eJ)(),parentSpanId:c||(0,s.eJ)().substring(16),spanId:(0,s.eJ)().substring(16),sampled:l,dsc:o||{}}:{traceId:a||(0,s.eJ)(),spanId:(0,s.eJ)().substring(16)}}function l(e=(0,s.eJ)(),t=(0,s.eJ)().substring(16),n){let i="";return void 0!==n&&(i=n?"-1":"-0"),`${e}-${t}${i}`}},6341:(e,t,n)=>{"use strict";function i(e){return e&&e.Math==Math?e:void 0}n.d(t,{BY:()=>r,OW:()=>s,VZ:()=>o});const s="object"==typeof globalThis&&i(globalThis)||"object"==typeof window&&i(window)||"object"==typeof self&&i(self)||"object"==typeof global&&i(global)||function(){return this}()||{};function o(){return s}function r(e,t,n){const i=n||s,o=i.__SENTRY__=i.__SENTRY__||{};return o[e]||(o[e]=t())}},6284:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var n={grad:.9,turn:360,rad:360/(2*Math.PI)},i=function(e){return"string"==typeof e?e.length>0:"number"==typeof e},s=function(e,t,n){return void 0===t&&(t=0),void 0===n&&(n=Math.pow(10,t)),Math.round(n*e)/n+0},o=function(e,t,n){return void 0===t&&(t=0),void 0===n&&(n=1),e>n?n:e>t?e:t},r=function(e){return(e=isFinite(e)?e%360:0)>0?e:e+360},a=function(e){return{r:o(e.r,0,255),g:o(e.g,0,255),b:o(e.b,0,255),a:o(e.a)}},c=function(e){return{r:s(e.r),g:s(e.g),b:s(e.b),a:s(e.a,3)}},l=/^#([0-9a-f]{3,8})$/i,g=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},d=function(e){var t=e.r,n=e.g,i=e.b,s=e.a,o=Math.max(t,n,i),r=o-Math.min(t,n,i),a=r?o===t?(n-i)/r:o===n?2+(i-t)/r:4+(t-n)/r:0;return{h:60*(a<0?a+6:a),s:o?r/o*100:0,v:o/255*100,a:s}},u=function(e){var t=e.h,n=e.s,i=e.v,s=e.a;t=t/360*6,n/=100,i/=100;var o=Math.floor(t),r=i*(1-n),a=i*(1-(t-o)*n),c=i*(1-(1-t+o)*n),l=o%6;return{r:255*[i,a,r,r,c,i][l],g:255*[c,i,i,a,r,r][l],b:255*[r,r,c,i,i,a][l],a:s}},b=function(e){return{h:r(e.h),s:o(e.s,0,100),l:o(e.l,0,100),a:o(e.a)}},I=function(e){return{h:s(e.h),s:s(e.s),l:s(e.l),a:s(e.a,3)}},p=function(e){return u((n=(t=e).s,{h:t.h,s:(n*=((i=t.l)<50?i:100-i)/100)>0?2*n/(i+n)*100:0,v:i+n,a:t.a}));var t,n,i},C=function(e){return{h:(t=d(e)).h,s:(s=(200-(n=t.s))*(i=t.v)/100)>0&&s<200?n*i/100/(s<=100?s:200-s)*100:0,l:s/2,a:t.a};var t,n,i,s},h=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,m=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,y=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Z=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,G={string:[[function(e){var t=l.exec(e);return t?(e=t[1]).length<=4?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:4===e.length?s(parseInt(e[3]+e[3],16)/255,2):1}:6===e.length||8===e.length?{r:parseInt(e.substr(0,2),16),g:parseInt(e.substr(2,2),16),b:parseInt(e.substr(4,2),16),a:8===e.length?s(parseInt(e.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(e){var t=y.exec(e)||Z.exec(e);return t?t[2]!==t[4]||t[4]!==t[6]?null:a({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:void 0===t[7]?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(e){var t=h.exec(e)||m.exec(e);if(!t)return null;var i,s,o=b({h:(i=t[1],s=t[2],void 0===s&&(s="deg"),Number(i)*(n[s]||1)),s:Number(t[3]),l:Number(t[4]),a:void 0===t[5]?1:Number(t[5])/(t[6]?100:1)});return p(o)},"hsl"]],object:[[function(e){var t=e.r,n=e.g,s=e.b,o=e.a,r=void 0===o?1:o;return i(t)&&i(n)&&i(s)?a({r:Number(t),g:Number(n),b:Number(s),a:Number(r)}):null},"rgb"],[function(e){var t=e.h,n=e.s,s=e.l,o=e.a,r=void 0===o?1:o;if(!i(t)||!i(n)||!i(s))return null;var a=b({h:Number(t),s:Number(n),l:Number(s),a:Number(r)});return p(a)},"hsl"],[function(e){var t=e.h,n=e.s,s=e.v,a=e.a,c=void 0===a?1:a;if(!i(t)||!i(n)||!i(s))return null;var l=function(e){return{h:r(e.h),s:o(e.s,0,100),v:o(e.v,0,100),a:o(e.a)}}({h:Number(t),s:Number(n),v:Number(s),a:Number(c)});return u(l)},"hsv"]]},B=function(e,t){for(var n=0;n=.5},e.prototype.toHex=function(){return t=(e=c(this.rgba)).r,n=e.g,i=e.b,r=(o=e.a)<1?g(s(255*o)):"","#"+g(t)+g(n)+g(i)+r;var e,t,n,i,o,r},e.prototype.toRgb=function(){return c(this.rgba)},e.prototype.toRgbString=function(){return t=(e=c(this.rgba)).r,n=e.g,i=e.b,(s=e.a)<1?"rgba("+t+", "+n+", "+i+", "+s+")":"rgb("+t+", "+n+", "+i+")";var e,t,n,i,s},e.prototype.toHsl=function(){return I(C(this.rgba))},e.prototype.toHslString=function(){return t=(e=I(C(this.rgba))).h,n=e.s,i=e.l,(s=e.a)<1?"hsla("+t+", "+n+"%, "+i+"%, "+s+")":"hsl("+t+", "+n+"%, "+i+"%)";var e,t,n,i,s},e.prototype.toHsv=function(){return e=d(this.rgba),{h:s(e.h),s:s(e.s),v:s(e.v),a:s(e.a,3)};var e},e.prototype.invert=function(){return R({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},e.prototype.saturate=function(e){return void 0===e&&(e=.1),R(W(this.rgba,e))},e.prototype.desaturate=function(e){return void 0===e&&(e=.1),R(W(this.rgba,-e))},e.prototype.grayscale=function(){return R(W(this.rgba,-1))},e.prototype.lighten=function(e){return void 0===e&&(e=.1),R(V(this.rgba,e))},e.prototype.darken=function(e){return void 0===e&&(e=.1),R(V(this.rgba,-e))},e.prototype.rotate=function(e){return void 0===e&&(e=15),this.hue(this.hue()+e)},e.prototype.alpha=function(e){return"number"==typeof e?R({r:(t=this.rgba).r,g:t.g,b:t.b,a:e}):s(this.rgba.a,3);var t},e.prototype.hue=function(e){var t=C(this.rgba);return"number"==typeof e?R({h:e,s:t.s,l:t.l,a:t.a}):s(t.h)},e.prototype.isEqual=function(e){return this.toHex()===R(e).toHex()},e}(),R=function(e){return e instanceof v?e:new v(e)},Y=[];t.Colord=v,t.colord=R,t.extend=function(e){e.forEach((function(e){Y.indexOf(e)<0&&(e(v,G),Y.push(e))}))},t.getFormat=function(e){return A(e)[1]},t.random=function(){return new v({r:255*Math.random(),g:255*Math.random(),b:255*Math.random()})}},6022:e=>{!function(){"use strict";var t=[,function(e,t){function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n255)throw new Error("Not ascii. Base64.encode can only take ascii strings.");e[n]=s}}for(var r=[],a=null,c=null,l=null,g=null,d=0;d>2&63,c=(3&e[d])<<4;break;case 1:c|=e[d]>>4&15,l=(15&e[d])<<2;break;case 2:l|=e[d]>>6&3,g=63&e[d],r.push(i(a)),r.push(i(c)),r.push(i(l)),r.push(i(g)),a=null,c=null,l=null,g=null}return null!=a&&(r.push(i(a)),r.push(i(c)),null==l?r.push("="):r.push(i(l)),null==g&&r.push("=")),r.join("")},decode:function(e){var t=Math.floor(3*e.length/4);"="==e.charAt(e.length-1)&&(t--,"="==e.charAt(e.length-2)&&t--);for(var i,s=o(t),r=null,a=null,c=null,l=0,g=0;g>4,s[l++]=r,a=(15&d)<<4;break;case 2:d>=0&&(a|=d>>2,s[l++]=a,c=(3&d)<<6);break;case 3:d>=0&&(s[l++]=c|d)}}return s},newBinary:o};t.Base64=r},function(e){e.exports={_noYieldsAllowed:function(e){return e()}}},function(e,t){function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function i(e){return JSON.stringify(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=function e(t,s,o,r,a){var c=s[t];switch(n(c)){case"string":return i(c);case"number":return isFinite(c)?String(c):"null";case"boolean":return String(c);case"object":if(!c)return"null";var l,g=r+o,d=[];if(Array.isArray(c)||{}.hasOwnProperty.call(c,"callee")){for(var u=c.length,b=0;b0&&void 0!==arguments[0]&&arguments[0]?a:(0,o.convertMapToObject)(a)},r._getConverters=function(){return c};var l=function(e){for(var t=0;t=d.length||s!==d[i]||!r.equals(e[s],t[d[i]],n)||(i++,0))}))):(i=0,a=g.every((function(s){return!!(0,o.hasOwn)(t,s)&&!!r.equals(e[s],t[s],n)&&(i++,!0)}))),a&&i===d.length},r.clone=function(e){var t;if(!(0,o.isObject)(e))return e;if(null===e)return null;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return e;if(r.isBinary(e)){t=r.newBinary(e.length);for(var n=0;n{"use strict";var t=Object.prototype.hasOwnProperty,n="~";function i(){}function s(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,t,i,o,r){if("function"!=typeof i)throw new TypeError("The listener must be a function");var a=new s(i,o||e,r),c=n?n+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function r(e,t){0==--e._eventsCount?e._events=new i:delete e._events[t]}function a(){this._events=new i,this._eventsCount=0}Object.create&&(i.prototype=Object.create(null),(new i).__proto__||(n=!1)),a.prototype.eventNames=function(){var e,i,s=[];if(0===this._eventsCount)return s;for(i in e=this._events)t.call(e,i)&&s.push(n?i.slice(1):i);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(e)):s},a.prototype.listeners=function(e){var t=n?n+e:e,i=this._events[t];if(!i)return[];if(i.fn)return[i.fn];for(var s=0,o=i.length,r=new Array(o);s{"use strict";e.exports=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var i,s,o;if(Array.isArray(t)){if((i=t.length)!=n.length)return!1;for(s=i;0!=s--;)if(!e(t[s],n[s]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((i=(o=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(s=i;0!=s--;)if(!Object.prototype.hasOwnProperty.call(n,o[s]))return!1;for(s=i;0!=s--;){var r=o[s];if(!e(t[r],n[r]))return!1}return!0}return t!=t&&n!=n}},4865:e=>{"use strict";const t=(e,t,i,s)=>{if("length"===i||"prototype"===i)return;if("arguments"===i||"caller"===i)return;const o=Object.getOwnPropertyDescriptor(e,i),r=Object.getOwnPropertyDescriptor(t,i);!n(o,r)&&s||Object.defineProperty(e,i,r)},n=function(e,t){return void 0===e||e.configurable||e.writable===t.writable&&e.enumerable===t.enumerable&&e.configurable===t.configurable&&(e.writable||e.value===t.value)},i=(e,t)=>`/* Wrapped ${e}*/\n${t}`,s=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),o=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name");e.exports=(e,n,{ignoreNonConfigurable:r=!1}={})=>{const{name:a}=e;for(const i of Reflect.ownKeys(n))t(e,n,i,r);return((e,t)=>{const n=Object.getPrototypeOf(t);n!==Object.getPrototypeOf(e)&&Object.setPrototypeOf(e,n)})(e,n),((e,t,n)=>{const r=""===n?"":`with ${n.trim()}() `,a=i.bind(null,r,t.toString());Object.defineProperty(a,"name",o),Object.defineProperty(e,"toString",{...s,value:a})})(e,n,a),e}},4617:e=>{"use strict";e.exports=(e,t)=>(t=t||(()=>{}),e.then((e=>new Promise((e=>{e(t())})).then((()=>e))),(e=>new Promise((e=>{e(t())})).then((()=>{throw e})))))},3290:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=n(228),s=n(7685),o=n(4774),r=()=>{},a=new s.TimeoutError;t.default=class extends i{constructor(e){var t,n,i,s;if(super(),this._intervalCount=0,this._intervalEnd=0,this._pendingCount=0,this._resolveEmpty=r,this._resolveIdle=r,!("number"==typeof(e=Object.assign({carryoverConcurrencyCount:!1,intervalCap:1/0,interval:0,concurrency:1/0,autoStart:!0,queueClass:o.default},e)).intervalCap&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${null!==(n=null===(t=e.intervalCap)||void 0===t?void 0:t.toString())&&void 0!==n?n:""}\` (${typeof e.intervalCap})`);if(void 0===e.interval||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${null!==(s=null===(i=e.interval)||void 0===i?void 0:i.toString())&&void 0!==s?s:""}\` (${typeof e.interval})`);this._carryoverConcurrencyCount=e.carryoverConcurrencyCount,this._isIntervalIgnored=e.intervalCap===1/0||0===e.interval,this._intervalCap=e.intervalCap,this._interval=e.interval,this._queue=new e.queueClass,this._queueClass=e.queueClass,this.concurrency=e.concurrency,this._timeout=e.timeout,this._throwOnTimeout=!0===e.throwOnTimeout,this._isPaused=!1===e.autoStart}get _doesIntervalAllowAnother(){return this._isIntervalIgnored||this._intervalCount{this._onResumeInterval()}),t)),!0;this._intervalCount=this._carryoverConcurrencyCount?this._pendingCount:0}return!1}_tryToStartAnother(){if(0===this._queue.size)return this._intervalId&&clearInterval(this._intervalId),this._intervalId=void 0,this._resolvePromises(),!1;if(!this._isPaused){const e=!this._isIntervalPaused();if(this._doesIntervalAllowAnother&&this._doesConcurrentAllowAnother){const t=this._queue.dequeue();return!!t&&(this.emit("active"),t(),e&&this._initializeIntervalIfNeeded(),!0)}}return!1}_initializeIntervalIfNeeded(){this._isIntervalIgnored||void 0!==this._intervalId||(this._intervalId=setInterval((()=>{this._onInterval()}),this._interval),this._intervalEnd=Date.now()+this._interval)}_onInterval(){0===this._intervalCount&&0===this._pendingCount&&this._intervalId&&(clearInterval(this._intervalId),this._intervalId=void 0),this._intervalCount=this._carryoverConcurrencyCount?this._pendingCount:0,this._processQueue()}_processQueue(){for(;this._tryToStartAnother(););}get concurrency(){return this._concurrency}set concurrency(e){if(!("number"==typeof e&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this._concurrency=e,this._processQueue()}async add(e,t={}){return new Promise(((n,i)=>{this._queue.enqueue((async()=>{this._pendingCount++,this._intervalCount++;try{const o=void 0===this._timeout&&void 0===t.timeout?e():s.default(Promise.resolve(e()),void 0===t.timeout?this._timeout:t.timeout,(()=>{(void 0===t.throwOnTimeout?this._throwOnTimeout:t.throwOnTimeout)&&i(a)}));n(await o)}catch(e){i(e)}this._next()}),t),this._tryToStartAnother(),this.emit("add")}))}async addAll(e,t){return Promise.all(e.map((async e=>this.add(e,t))))}start(){return this._isPaused?(this._isPaused=!1,this._processQueue(),this):this}pause(){this._isPaused=!0}clear(){this._queue=new this._queueClass}async onEmpty(){if(0!==this._queue.size)return new Promise((e=>{const t=this._resolveEmpty;this._resolveEmpty=()=>{t(),e()}}))}async onIdle(){if(0!==this._pendingCount||0!==this._queue.size)return new Promise((e=>{const t=this._resolveIdle;this._resolveIdle=()=>{t(),e()}}))}get size(){return this._queue.size}sizeBy(e){return this._queue.filter(e).length}get pending(){return this._pendingCount}get isPaused(){return this._isPaused}get timeout(){return this._timeout}set timeout(e){this._timeout=e}}},9998:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,n){let i=0,s=e.length;for(;s>0;){const o=s/2|0;let r=i+o;n(e[r],t)<=0?(i=++r,s-=o+1):s=o}return i}},4774:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=n(9998);t.default=class{constructor(){this._queue=[]}enqueue(e,t){const n={priority:(t=Object.assign({priority:0},t)).priority,run:e};if(this.size&&this._queue[this.size-1].priority>=t.priority)return void this._queue.push(n);const s=i.default(this._queue,n,((e,t)=>t.priority-e.priority));this._queue.splice(s,0,n)}dequeue(){const e=this._queue.shift();return null==e?void 0:e.run}filter(e){return this._queue.filter((t=>t.priority===e.priority)).map((e=>e.run))}get size(){return this._queue.length}}},7685:(e,t,n)=>{"use strict";const i=n(4617);class s extends Error{constructor(e){super(e),this.name="TimeoutError"}}const o=(e,t,n)=>new Promise(((o,r)=>{if("number"!=typeof t||t<0)throw new TypeError("Expected `milliseconds` to be a positive number");if(t===1/0)return void o(e);const a=setTimeout((()=>{if("function"==typeof n){try{o(n())}catch(e){r(e)}return}const i=n instanceof Error?n:new s("string"==typeof n?n:`Promise timed out after ${t} milliseconds`);"function"==typeof e.cancel&&e.cancel(),r(i)}),t);i(e.then(o,r),(()=>{clearTimeout(a)}))}));e.exports=o,e.exports.default=o,e.exports.TimeoutError=s},7194:e=>{"use strict";e.exports=require("dgram")},1637:e=>{"use strict";e.exports=require("diagnostics_channel")},1943:e=>{"use strict";e.exports=require("fs/promises")},8611:e=>{"use strict";e.exports=require("http")},5692:e=>{"use strict";e.exports=require("https")},264:e=>{"use strict";e.exports=require("inspector")},9278:e=>{"use strict";e.exports=require("net")},6928:e=>{"use strict";e.exports=require("path")},2203:e=>{"use strict";e.exports=require("stream")},7016:e=>{"use strict";e.exports=require("url")},4581:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},4326:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.runEntrypoint=void 0;const i=n(1635),s=n(9967),o=i.__importDefault(n(1943)),r=n(360),a=n(2710);n(5664);const c=n(4044),l=i.__importDefault(n(6928));let g,d=!1;t.runEntrypoint=function(e,t){Promise.resolve().then((async()=>{if(d)throw new Error("runEntrypoint can only be called once");d=!0;const n=process.env.MODULE_MANIFEST;if(!n)throw new Error("Module initialise is missing MODULE_MANIFEST");const i=await o.default.readFile(n),u=JSON.parse(i.toString());if(u.runtime?.api!==s.HostApiNodeJsIpc)throw new Error("Module manifest 'api' mismatch");if(!u.runtime.apiVersion)throw new Error("Module manifest 'apiVersion' missing");let b=u.runtime.apiVersion;if("0.0.0"===b)try{const e=await o.default.readFile(l.default.join(__dirname,"../package.json")),t=JSON.parse(e.toString());"@companion-module/base"===t.name&&(b=t.version)}catch(e){throw new Error("Failed to determine module api version")}if(!process.send)throw new Error("Module is not being run with ipc");console.log(`Starting up module class: ${e.name}`);const I=process.env.CONNECTION_ID;if("string"!=typeof I||!I)throw new Error("Module initialise is missing CONNECTION_ID");const p=process.env.VERIFICATION_TOKEN;if("string"!=typeof p||!p)throw new Error("Module initialise is missing VERIFICATION_TOKEN");const C=process.env.SENTRY_DSN,h=process.env.SENTRY_USERID,m=process.env.SENTRY_COMPANION_VERSION;C&&h&&"https://"==C.substring(0,8)?(console.log("Sentry enabled"),(0,a.init)({dsn:C,release:`${u.name}@${u.version}`,beforeSend:e=>(e.exception&&console.log("sentry","error",e.exception),e)}),(0,a.configureScope)((e=>{e.setUser({id:h}),e.setTag("companion",m)}))):console.log("Sentry disabled");const y=new c.IpcWrapper({},(e=>{process.send(e)}),5e3);process.once("message",(e=>{y.receivedMessage(e)})),g=new e((0,r.literal)({id:I,upgradeScripts:t,_isInstanceBaseProps:!0})),y.sendWithCb("register",{apiVersion:b,connectionId:I,verificationToken:p}).then((()=>{console.log("Module-host accepted registration")}),(e=>{console.error("Module registration failed",e),process.exit(11)}))})).catch((e=>{console.error("Failed to startup module:"),console.error(e.stack||e.message),process.exit(1)}))}},6160:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.UDPHelper=t.TelnetHelper=t.TCPHelper=void 0;var i=n(8895);Object.defineProperty(t,"TCPHelper",{enumerable:!0,get:function(){return i.TCPHelper}});var s=n(1118);Object.defineProperty(t,"TelnetHelper",{enumerable:!0,get:function(){return s.TelnetHelper}});var o=n(6259);Object.defineProperty(t,"UDPHelper",{enumerable:!0,get:function(){return o.UDPHelper}})},8895:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TCPHelper=void 0;const i=n(1635).__importDefault(n(9278)),s=n(228),o=n(1400);class r extends s.EventEmitter{#e;#t;_socket;#n;#i=!1;#s=!1;#o=!1;#r;#a;#c;get isConnected(){return this.#i}get isConnecting(){return this.#s}get isDestroyed(){return this.#o}constructor(e,t,n){super(),this.#e=e,this.#t=t,this.#n={reconnect_interval:2e3,reconnect:!0,...n},this._socket=new i.default.Socket,this._socket.setKeepAlive(!0),this._socket.setNoDelay(!0),this._socket.on("error",(e=>{this.#s=!1,this.#i=!1,this.#n.reconnect&&this.#l(),this.#g(o.InstanceStatus.UnknownError,e.message),this.emit("error",e)})),this._socket.on("ready",(()=>{this.#i=!0,this.#s=!1,this.#g(o.InstanceStatus.Ok),this.emit("connect")})),this._socket.on("end",(()=>{this.#i=!1,this.#g(o.InstanceStatus.Disconnected),!this.#s&&this.#n.reconnect&&this.#l(),this.emit("end")})),this._socket.on("data",(e=>this.emit("data",e))),this._socket.on("drain",(()=>this.emit("drain"))),setImmediate((()=>this.connect())),this.#c=setTimeout((()=>{this.#c=void 0,this.#o||this.listenerCount("error")||console.error(`Danger: TCP client for ${this.#e}:${this.#t} is missing an error handler!`)}),5e3)}connect(){if(this.#o)throw new Error("Cannot connect destroyed socket");return!this.#s&&(this.#s=!0,this._socket.connect(this.#t,this.#e),!0)}async send(e){if(this.#o||this._socket.destroyed)throw new Error("Cannot write to destroyed socket");if(!e||!e.length)throw new Error("No message to send");if(!this.#i)return!1;try{return new Promise(((t,n)=>{this._socket.write(e,(e=>{e?n(e):t(!0)}))}))}catch(e){this.#i=!1;const t=e instanceof Error?e:new Error(`${e}`);throw this.#g(o.InstanceStatus.UnknownError,t.message),this.emit("error",t),t}}destroy(){this.#o=!0,void 0!==this.#a&&(clearTimeout(this.#a),this.#a=void 0),void 0!==this.#c&&(clearTimeout(this.#c),this.#c=void 0),this._socket.removeAllListeners(),this.removeAllListeners(),this._socket.destroy()}#l(){void 0!==this.#a&&clearTimeout(this.#a),this.#a=setTimeout((()=>{this.#a=void 0,this.#g(o.InstanceStatus.Connecting),this.connect()}),this.#n.reconnect_interval)}#g(e,t){this.#r!=e&&(this.#r=e,this.emit("status_change",e,t))}}t.TCPHelper=r},1118:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TelnetHelper=void 0;const i=n(1635).__importDefault(n(228)),s=n(2203),o=n(8895);class r extends i.default{#d;#u;#c;get isConnected(){return this.#d.isConnected}get isConnecting(){return this.#d.isConnecting}get isDestroyed(){return this.#d.isDestroyed}constructor(e,t,n){super(),this.#d=new o.TCPHelper(e,t,n),this.#u=new a,this.#d._socket.pipe(this.#u),this.#d.on("connect",(()=>this.emit("connect"))),this.#d.on("end",(()=>this.emit("end"))),this.#d.on("error",(e=>this.emit("error",e))),this.#d.on("status_change",((e,t)=>this.emit("status_change",e,t))),this.#u.on("iac",((e,t)=>this.emit("iac",e,t))),this.#u.on("sb",(e=>this.emit("sb",e))),this.#u.on("data",(e=>this.emit("data",e))),this.#u.on("drain",(()=>this.emit("drain"))),this.#c=setTimeout((()=>{this.#c=void 0,this.isDestroyed||this.listenerCount("error")||console.error(`Danger: Telnet client for ${e}:${t} is missing an error handler!`)}),5e3)}connect(){return this.#d.connect()}async send(e){return this.#d.send(e)}destroy(){this.#d.destroy(),void 0!==this.#c&&(clearTimeout(this.#c),this.#c=void 0),this.#u.removeAllListeners(),this.#u.destroy()}}t.TelnetHelper=r;class a extends s.Transform{#b;#I;#p;constructor(e){super(e),this.#b=Buffer.alloc(0),this.#I=Buffer.alloc(0),this.#p=0}_transform(e,t,n){for(let t=0;t=251&&this.#p<=254){let t;switch(this.#p){case 251:t="WILL";break;case 252:t="WONT";break;case 253:t="DO";break;case 254:t="DONT";break;default:return}return this.emit("iac",t,e),void(this.#p=0)}if(250===this.#p){if(240===e)return this.emit("sb",this.#I),this.#p=0,void(this.#I=Buffer.alloc(0));this.#I=Buffer.concat([this.#I,Buffer.from([e])])}}}#h(){const e=this.#b;return this.#b=Buffer.alloc(0),e}}},6259:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.UDPHelper=void 0;const i=n(1635).__importDefault(n(7194)),s=n(228),o=n(1400);class r extends s.EventEmitter{#e;#t;#m;#n;#o=!1;#r;#c;get isDestroyed(){return this.#o}constructor(e,t,n){super(),this.#e=e,this.#t=t,this.#n={...n},this.#m=i.default.createSocket("udp4");try{this.#m.bind(this.#n.bind_port||0,this.#n.bind_ip)}catch(e){throw new Error(`Unable to bind to ip/port: ${this.#n.bind_ip}:${this.#n.bind_port}`)}this.#n.broadcast&&this.#m.setBroadcast(!0),void 0!==this.#n.ttl&&this.#m.setTTL(this.#n.ttl),void 0!==this.#n.multicast_ttl&&this.#m.setMulticastTTL(this.#n.multicast_ttl),this.#m.on("error",(e=>{this.#g(o.InstanceStatus.UnknownError,e.message),this.emit("error",e)})),this.#m.on("listening",(()=>{this.#n.multicast_interface&&this.#m.setMulticastInterface(this.#n.multicast_interface),this.#g(o.InstanceStatus.Ok),this.emit("listening")})),this.#m.on("message",(e=>this.emit("data",e))),this.#c=setTimeout((()=>{this.#o||this.listenerCount("error")||console.error(`Danger: UDP socket for ${this.#e}:${this.#t} is missing an error handler!`)}),5e3)}async send(e){if(this.#o)throw new Error("Cannot write to destroyed socket");if(!e||!e.length)throw new Error("No message to send");return new Promise(((t,n)=>{this.#m.send(e,this.#t,this.#e,(e=>{e?n(e):t()}))}))}destroy(){this.#o=!0,void 0!==this.#c&&(clearTimeout(this.#c),this.#c=void 0),this.#m.removeAllListeners(),this.#m.close(),this.removeAllListeners()}#g(e,t){this.#r!=e&&(this.#r=e,this.emit("status_change",e,t))}}t.UDPHelper=r},4044:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.IpcWrapper=void 0;const i=n(1635),s=n(360),o=i.__importDefault(n(6022));t.IpcWrapper=class{#y;#Z;#G;#B=1;#A=new Map;constructor(e,t,n){this.#y=e,this.#Z=t,this.#G=n}async sendWithCb(e,t,n,i=0){i<=0&&(i=this.#G);const s={timeout:void 0,resolve:()=>null,reject:()=>null},r=new Promise(((e,t)=>{s.resolve=e,s.reject=t}));this.#B>268435456&&(this.#B=1);const a=this.#B++;this.#A.set(a,s),this.#Z({direction:"call",name:String(e),payload:o.default.stringify(t),callbackId:a});const c=new Error("Call timed out");return s.timeout=setTimeout((()=>{s.reject(n?n():c),this.#A.delete(a)}),i),r}sendWithNoCb(e,t){this.#Z({direction:"call",name:String(e),payload:o.default.stringify(t),callbackId:void 0})}receivedMessage(e){const t=e;switch(e.direction){case"call":{const t=this.#y[e.name];if(!t)return void(e.callbackId&&this.#Z({direction:"response",callbackId:e.callbackId,success:!1,payload:o.default.stringify({message:`Unknown command "${e.name}"`})}));t(e.payload?o.default.parse(e.payload):void 0).then((t=>{e.callbackId&&this.#Z({direction:"response",callbackId:e.callbackId,success:!0,payload:o.default.stringify(t)})}),(t=>{e.callbackId&&this.#Z({direction:"response",callbackId:e.callbackId,success:!1,payload:t instanceof Error?JSON.stringify(t,Object.getOwnPropertyNames(t)):o.default.stringify(t)})}));break}case"response":{if(!e.callbackId)return void console.error("Ipc: Response message has no callbackId");const t=this.#A.get(e.callbackId);if(this.#A.delete(e.callbackId),!t)return;clearTimeout(t.timeout);const n=e.payload?o.default.parse(e.payload):void 0;if(e.success)t.resolve(n);else{let e=n;n&&"object"==typeof n&&"message"in n&&(e=new Error(n.message),n.stack&&(e.stack=n.stack)),t.reject(e)}break}default:(0,s.assertNever)(e),console.error(`Ipc: Message of unknown direction "${t.direction}"`)}}}},9967:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HostApiNodeJsIpc=void 0,t.HostApiNodeJsIpc="nodejs-ipc"},6278:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.runEntrypoint=t.assertNever=t.splitHex=t.splitHsv=t.splitHsl=t.splitRgb=t.combineRgb=t.literal=void 0;const i=n(1635);i.__exportStar(n(9077),t),i.__exportStar(n(2018),t),i.__exportStar(n(4581),t);var s=n(360);Object.defineProperty(t,"literal",{enumerable:!0,get:function(){return s.literal}}),Object.defineProperty(t,"combineRgb",{enumerable:!0,get:function(){return s.combineRgb}}),Object.defineProperty(t,"splitRgb",{enumerable:!0,get:function(){return s.splitRgb}}),Object.defineProperty(t,"splitHsl",{enumerable:!0,get:function(){return s.splitHsl}}),Object.defineProperty(t,"splitHsv",{enumerable:!0,get:function(){return s.splitHsv}}),Object.defineProperty(t,"splitHex",{enumerable:!0,get:function(){return s.splitHex}}),Object.defineProperty(t,"assertNever",{enumerable:!0,get:function(){return s.assertNever}}),i.__exportStar(n(6160),t);var o=n(4326);Object.defineProperty(t,"runEntrypoint",{enumerable:!0,get:function(){return o.runEntrypoint}})},4289:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ActionManager=void 0;const i=n(2593);function s(e){return{id:e.id,actionId:e.actionId,controlId:e.controlId,options:e.options}}t.ActionManager=class{#W;#f;#V;#v=new Map;#R=new Map;constructor(e,t,n){this.#W=e,this.#f=t,this.#V=n}async handleExecuteAction(e){const t=this.#v.get(e.action.actionId);if(!t)throw new Error(`Unknown action: ${e.action.actionId}`);const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.action.controlId,actionInstanceId:e.action.id,feedbackInstanceId:void 0})).text};await t.callback({id:e.action.id,actionId:e.action.actionId,controlId:e.action.controlId,options:e.action.options,surfaceId:e.surfaceId},n)}handleUpdateActions(e){for(const[t,n]of Object.entries(e)){const e=this.#R.get(t);if(e){const t=this.#v.get(e.actionId);if(t?.unsubscribe){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.controlId,actionInstanceId:e.id,feedbackInstanceId:void 0})).text};Promise.resolve(t.unsubscribe(s(e),n)).catch((t=>{this.#V("error",`Action unsubscribe failed: ${JSON.stringify(e)} - ${t?.message??t} ${t?.stack}`)}))}}if(!n||n.disabled)this.#R.delete(t);else{this.#R.set(t,n);const e=this.#v.get(n.actionId);if(e?.subscribe){const t={parseVariablesInString:async e=>(await this.#W({text:e,controlId:n.controlId,actionInstanceId:n.id,feedbackInstanceId:void 0})).text};Promise.resolve(e.subscribe(s(n),t)).catch((e=>{this.#V("error",`Action subscribe failed: ${JSON.stringify(n)} - ${e?.message??e} ${e?.stack}`)}))}}}}async handleLearnAction(e){const t=this.#v.get(e.action.actionId);if(t&&t.learn){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.action.controlId,actionInstanceId:e.action.id,feedbackInstanceId:void 0})).text};return{options:await t.learn({id:e.action.id,actionId:e.action.actionId,controlId:e.action.controlId,options:e.action.options,surfaceId:void 0},n)}}return{options:void 0}}setActionDefinitions(e){const t=[];this.#v.clear();for(const[n,s]of Object.entries(e))s&&(t.push({id:n,name:s.name,description:s.description,options:(0,i.serializeIsVisibleFn)(s.options),hasLearn:!!s.learn,learnTimeout:s.learnTimeout}),this.#v.set(n,s));this.#f({actions:t})}_getAllActions(){return Array.from(this.#R.values()).map((e=>({id:e.id,actionId:e.actionId,controlId:e.controlId,options:e.options})))}subscribeActions(e){let t=Array.from(this.#R.values());const n=new Set(e);n.size&&(t=t.filter((e=>n.has(e.actionId))));for(const e of t){const t=this.#v.get(e.actionId);if(t?.subscribe){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.controlId,actionInstanceId:e.id,feedbackInstanceId:void 0})).text};Promise.resolve(t.subscribe(s(e),n)).catch((t=>{this.#V("error",`Action subscribe failed: ${JSON.stringify(e)} - ${t?.message??t} ${t?.stack}`)}))}}}unsubscribeActions(e){let t=Array.from(this.#R.values());const n=new Set(e);n.size&&(t=t.filter((e=>n.has(e.actionId))));for(const e of t){const t=this.#v.get(e.actionId);if(t&&t.unsubscribe){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.controlId,actionInstanceId:e.id,feedbackInstanceId:void 0})).text};Promise.resolve(t.unsubscribe(s(e),n)).catch((t=>{this.#V("error",`Action unsubscribe failed: ${JSON.stringify(e)} - ${t?.message??t} ${t?.stack}`)}))}}}}},2593:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isInstanceBaseProps=t.serializeIsVisibleFn=void 0,t.serializeIsVisibleFn=function(e){return(e??[]).map((e=>"isVisible"in e&&"function"==typeof e.isVisible?{...e,isVisibleFn:e.isVisible.toString(),isVisible:void 0}:{...e,isVisibleFn:void 0}))},t.isInstanceBaseProps=function(e){const t=e;return"object"==typeof t&&"string"==typeof t.id&&!0===t._isInstanceBaseProps}},8039:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FeedbackManager=void 0;const i=n(1635),s=n(2593),o=i.__importDefault(n(7e3));function r(e,t){return{type:e,id:t.id,feedbackId:t.feedbackId,controlId:t.controlId,options:t.options}}t.FeedbackManager=class{#W;#Y;#X;#V;#H=new Map;#S=new Map;#N=new Map;#w=new Map;#K;get parseVariablesContext(){return this.#K}constructor(e,t,n,i){this.#W=e,this.#Y=t,this.#X=n,this.#V=i}getDefinitionIds(){return Array.from(this.#H.keys())}getInstanceIds(){return Array.from(this.#S.keys())}handleUpdateFeedbacks(e){for(const[t,n]of Object.entries(e)){const e=this.#S.get(t);if(e){const t=this.#H.get(e.feedbackId);if(t?.unsubscribe){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.controlId,actionInstanceId:void 0,feedbackInstanceId:e.id})).text};Promise.resolve(t.unsubscribe(r(t.type,e),n)).catch((t=>{this.#V("error",`Feedback unsubscribe failed: ${JSON.stringify(e)} - ${t?.message??t} ${t?.stack}`)}))}}if(!n||n.disabled)this.#S.delete(t);else{this.#S.set(t,{...n,referencedVariables:null});const e=this.#H.get(n.feedbackId);if(e?.subscribe){const t={parseVariablesInString:async e=>(await this.#W({text:e,controlId:n.controlId,actionInstanceId:void 0,feedbackInstanceId:n.id})).text};Promise.resolve(e.subscribe(r(e.type,n),t)).catch((e=>{this.#V("error",`Feedback subscribe failed: ${JSON.stringify(n)} - ${e?.message??e} ${e?.stack}`)}))}this.#F(t)}}}async handleLearnFeedback(e){const t=this.#H.get(e.feedback.feedbackId);if(t&&t.learn){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.feedback.controlId,actionInstanceId:void 0,feedbackInstanceId:e.feedback.id})).text};return{options:await t.learn({id:e.feedback.id,feedbackId:e.feedback.feedbackId,controlId:e.feedback.controlId,options:e.feedback.options,type:t.type},n)}}return{options:void 0}}handleVariablesChanged(e){if(!e.variablesIds.length)return;const t=new Set(e.variablesIds);for(const t of this.#w.values())for(const n of e.variablesIds)t.changedVariables.add(n);const n=new Set;for(const e of this.#S.values())if(!this.#w.has(e.id)&&e.referencedVariables)for(const i of e.referencedVariables)if(t.has(i)){n.add(e.id);break}for(const e of n)setImmediate((()=>{this.#F(e)}))}#F(e){const t=this.#w.get(e);if(t)return void(t.needsRecheck=!0);const n=this.#S.get(e);if(!n)return;const i=n,s={needsRecheck:!1,changedVariables:new Set};this.#w.set(e,s),Promise.resolve().then((async()=>{const t=this.#H.get(i.feedbackId);let n;const s=new Set;if(t){this.#K=`Feedback ${i.feedbackId} (${e})`;const o={parseVariablesInString:async t=>{const n=await this.#W({text:t,controlId:i.controlId,actionInstanceId:void 0,feedbackInstanceId:e});if(n.variableIds&&n.variableIds.length)for(const e of n.variableIds)s.add(e);return n.text}};n="boolean"===t.type?t.callback({...r("boolean",i),type:"boolean"},o):t.callback({...r("advanced",i),type:"advanced",image:i.image},o),this.#K=void 0}const o=await n;this.#N.set(e,{id:e,controlId:i.controlId,value:o}),this.#k(),i.referencedVariables=s.size>0?Array.from(s):null})).catch((e=>{console.error(`Feedback check failed: ${JSON.stringify(i)} - ${e?.message??e} ${e?.stack}`)})).finally((()=>{this.#K=void 0,this.#w.delete(e);let t=!1;if(i.referencedVariables)for(const e of i.referencedVariables)if(s.changedVariables.has(e)){t=!0;break}(t||s.needsRecheck)&&setImmediate((()=>{this.#F(e)}))}))}#k=(0,o.default)((()=>{const e=this.#N;this.#N=new Map,e.size>0&&this.#Y({values:Array.from(e.values())})}),{wait:5,maxWait:25});setFeedbackDefinitions(e){const t=[];this.#H.clear();for(const[n,i]of Object.entries(e))i&&(t.push({id:n,name:i.name,description:i.description,options:(0,s.serializeIsVisibleFn)(i.options),type:i.type,defaultStyle:"boolean"===i.type?i.defaultStyle:void 0,hasLearn:!!i.learn,learnTimeout:i.learnTimeout,showInvert:"boolean"===i.type&&i.showInvert}),this.#H.set(n,i));this.#X({feedbacks:t})}checkFeedbacks(e){const t=new Set(e);for(const[e,n]of this.#S.entries())this.#H.get(n.feedbackId)&&(0===t.size||t.has(n.feedbackId))&&this.#F(e)}checkFeedbacksById(e){for(const t of e)this.#F(t)}_getAllFeedbacks(){return Array.from(this.#S.values()).map((e=>({id:e.id,feedbackId:e.feedbackId,controlId:e.controlId,options:e.options})))}subscribeFeedbacks(e){let t=Array.from(this.#S.values());const n=new Set(e);n.size&&(t=t.filter((e=>n.has(e.feedbackId))));for(const e of t){const t=this.#H.get(e.feedbackId);if(t?.subscribe){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.controlId,actionInstanceId:void 0,feedbackInstanceId:e.id})).text};Promise.resolve(t.subscribe(r(t.type,e),n)).catch((t=>{this.#V("error",`Feedback subscribe failed: ${JSON.stringify(e)} - ${t?.message??t} ${t?.stack}`)}))}}}unsubscribeFeedbacks(e){let t=Array.from(this.#S.values());const n=new Set(e);n.size&&(t=t.filter((e=>n.has(e.feedbackId))));for(const e of t){const t=this.#H.get(e.feedbackId);if(t&&t.unsubscribe){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.controlId,actionInstanceId:void 0,feedbackInstanceId:e.id})).text};Promise.resolve(t.unsubscribe(r(t.type,e),n)).catch((t=>{this.#V("error",`Feedback unsubscribe failed: ${JSON.stringify(e)} - ${t?.message??t} ${t?.stack}`)}))}}}}},1706:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.runThroughUpgradeScripts=void 0;const i=n(360);function s(e){return JSON.parse(JSON.stringify(e))}t.runThroughUpgradeScripts=function(e,t,n,o,r,a){const c=new Map,l=e=>{let t=c.get(e);return t||(t={actions:[],feedbacks:[],config:!1},c.set(e,t)),t};for(const t of Object.values(e)){const e=t?.upgradeIndex??n;t&&"number"==typeof e&&l(e).actions.push(t.id)}for(const e of Object.values(t)){const t=e?.upgradeIndex??n;e&&"number"==typeof t&&l(t).feedbacks.push(e.id)}if(!a)for(let e=n??-1;e0){const a=Array.from(c.keys()).sort(),l=Math.min(...a,n??-1)+1,b=[],I=[],p=o.length;for(let n=l;n{const n=e[t];if(n)return(0,i.literal)({id:n.id,controlId:n.controlId,actionId:n.actionId,options:void 0!==n.options?s(n.options):{}})})).filter((e=>!!e)),feedbacks:I.map((e=>{const n=t[e];if(n)return(0,i.literal)({id:n.id,controlId:n.controlId,feedbackId:n.feedbackId,options:void 0!==n.options?s(n.options):{},isInverted:n.isInverted})})).filter((e=>!!e))});l&&C.updatedConfig&&(u=C.updatedConfig);for(const t of C.updatedActions)if(t){const n=e[t.id];n&&(n.actionId=t.actionId,n.options=t.options,d[t.id]=n)}for(const e of C.updatedFeedbacks)if(e){const n=t[e.id];n&&(n.feedbackId=e.feedbackId,n.options=e.options,g[e.id]={...n,style:g[e.id]?.style??e.style,isInverted:e.isInverted??!1})}}for(const[t,n]of Object.entries(e))d[t]||"number"!=typeof n?.upgradeIndex||(d[t]=n);for(const[e,n]of Object.entries(t))g[e]||"number"!=typeof n?.upgradeIndex||(g[e]=n)}return{updatedActions:d,updatedFeedbacks:g,updatedConfig:u}}},9077:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.validateManifest=void 0;const i=n(1635).__importDefault(n(7281));t.validateManifest=function(e){const t=JSON.stringify(e);if(t.includes("companion-module-your-module-name"))throw new Error("Manifest incorrectly references template module 'companion-module-your-module-name'");if(t.includes("module-shortname"))throw new Error("Manifest incorrectly references template module 'module-shortname'");if(t.includes("A short one line description of your module"))throw new Error("Manifest incorrectly references template module 'A short one line description of your module'");if(t.includes("Your name"))throw new Error("Manifest incorrectly references template module 'Your name'");if(t.includes("Your email"))throw new Error("Manifest incorrectly references template module 'Your email'");if(t.includes("Your company"))throw new Error("Manifest incorrectly references template module 'Your company'");if(t.includes("Your product"))throw new Error("Manifest incorrectly references template module 'Your product'");if(!(0,i.default)(e)){const e=i.default.errors;if(!e)throw new Error("Manifest failed validation with unknown reason");throw new Error(`Manifest validation failed: ${JSON.stringify(e)}`)}}},3730:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},1649:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.InstanceBase=void 0;const i=n(1635),s=n(360),o=i.__importDefault(n(3290)),r=n(2593),a=n(1706),c=n(8039),l=n(4044),g=n(4289);t.InstanceBase=class{#_;#J;id;#z=new o.default({concurrency:1});#U=!1;#x=!1;#T={};#E;#Q;#L=new Map;#j=new Map;#n;#O;get instanceOptions(){return this.#n}get label(){return this.#O}constructor(e){if(!(0,r.isInstanceBaseProps)(e)||!e._isInstanceBaseProps)throw new Error("Module instance is being constructed incorrectly. Make sure you aren't trying to do this manually");this.#n={disableVariableValidation:!1},this.#_=new l.IpcWrapper({init:this._handleInit.bind(this),destroy:this._handleDestroy.bind(this),updateConfigAndLabel:this._handleConfigUpdateAndLabel.bind(this),updateConfig:async()=>{},executeAction:this._handleExecuteAction.bind(this),updateFeedbacks:this._handleUpdateFeedbacks.bind(this),updateActions:this._handleUpdateActions.bind(this),getConfigFields:this._handleGetConfigFields.bind(this),handleHttpRequest:this._handleHttpRequest.bind(this),learnAction:this._handleLearnAction.bind(this),learnFeedback:this._handleLearnFeedback.bind(this),startStopRecordActions:this._handleStartStopRecordActions.bind(this),variablesChanged:this._handleVariablesChanged.bind(this)},(e=>{process.send(e)}),5e3),process.on("message",(e=>{this.#_.receivedMessage(e)})),this.#E=new g.ActionManager((async e=>this.#_.sendWithCb("parseVariablesInString",e)),(e=>this.#_.sendWithNoCb("setActionDefinitions",e)),this.log.bind(this)),this.#Q=new c.FeedbackManager((async e=>this.#_.sendWithCb("parseVariablesInString",e)),(e=>this.#_.sendWithNoCb("updateFeedbackValues",e)),(e=>this.#_.sendWithNoCb("setFeedbackDefinitions",e)),this.log.bind(this)),this.#J=e.upgradeScripts,this.id=e.id,this.#O=e.id,this.log("debug","Initializing")}async _handleInit(e){return this.#z.add((async()=>{if(this.#U)throw new Error("Already initialized");const t=e.actions,n=e.feedbacks;if(this.#T=e.config,this.#O=e.label,e.isFirstInit){const t={},n=this.getConfigFields();for(const e of n)"default"in e&&(t[e.id]=e.default);this.#T=t,this.saveConfig(this.#T),e.lastUpgradeIndex=this.#J.length-1}const{updatedActions:i,updatedFeedbacks:s,updatedConfig:o}=(0,a.runThroughUpgradeScripts)(t,n,e.lastUpgradeIndex,this.#J,this.#T,!1);this.#T=o??this.#T;const r=this.#_.sendWithCb("upgradedItems",{updatedActions:i,updatedFeedbacks:s});try{await this.init(this.#T,!!e.isFirstInit),this.#U=!0}catch(e){throw console.trace(`Init failed: ${e}`),e}finally{await r}return setImmediate((()=>{this._handleUpdateActions({actions:t},!0).catch((e=>{this.log("error",`Receive actions failed: ${e}`)})),this._handleUpdateFeedbacks({feedbacks:n},!0).catch((e=>{this.log("error",`Receive feedbacks failed: ${e}`)}))})),{hasHttpHandler:"function"==typeof this.handleHttpRequest,hasRecordActionsHandler:"function"==typeof this.handleStartStopRecordActions,newUpgradeIndex:this.#J.length-1,updatedConfig:this.#T}}))}async _handleDestroy(){await this.#z.add((async()=>{if(!this.#U)throw new Error("Not initialized");await this.destroy(),this.#U=!1}))}async _handleConfigUpdateAndLabel(e){await this.#z.add((async()=>{if(!this.#U)throw new Error("Not initialized");this.#O=e.label,this.#T=e.config,await this.configUpdated(this.#T)}))}async _handleExecuteAction(e){return this.#E.handleExecuteAction(e)}async _handleUpdateFeedbacks(e,t){if(!t){const t=(0,a.runThroughUpgradeScripts)({},e.feedbacks,null,this.#J,this.#T,!0);this.#_.sendWithCb("upgradedItems",{updatedActions:t.updatedActions,updatedFeedbacks:t.updatedFeedbacks}).catch((e=>{this.log("error",`Failed to save upgraded feedbacks: ${e}`)}))}this.#Q.handleUpdateFeedbacks(e.feedbacks)}async _handleUpdateActions(e,t){if(!t){const t=(0,a.runThroughUpgradeScripts)(e.actions,{},null,this.#J,this.#T,!0);this.#_.sendWithCb("upgradedItems",{updatedActions:t.updatedActions,updatedFeedbacks:t.updatedFeedbacks}).catch((e=>{this.log("error",`Failed to save upgraded actions: ${e}`)}))}this.#E.handleUpdateActions(e.actions)}async _handleGetConfigFields(e){return{fields:(0,r.serializeIsVisibleFn)(this.getConfigFields())}}async _handleHttpRequest(e){if(!this.handleHttpRequest)throw new Error("handleHttpRequest is not supported!");return{response:await this.handleHttpRequest(e.request)}}async _handleLearnAction(e){return this.#E.handleLearnAction(e)}async _handleLearnFeedback(e){return this.#Q.handleLearnFeedback(e)}async _handleStartStopRecordActions(e){if(e.recording){if(this.#x)return}else if(!this.#x)return;if(!this.handleStartStopRecordActions)throw this.#x=!1,new Error("Recording actions is not supported by this module!");this.#x=e.recording,this.handleStartStopRecordActions(this.#x)}async _handleVariablesChanged(e){this.#Q.handleVariablesChanged(e)}saveConfig(e){this.#T=e,this.#_.sendWithNoCb("saveConfig",{config:e})}setActionDefinitions(e){this.#E.setActionDefinitions(e)}setFeedbackDefinitions(e){this.#Q.setFeedbackDefinitions(e)}setPresetDefinitions(e){const t=[];for(const[n,i]of Object.entries(e))i&&t.push({...i,id:n});this.#_.sendWithNoCb("setPresetDefinitions",{presets:t})}setVariableDefinitions(e){const t=[],n=[];this.#L.clear();for(const i of e)t.push({id:i.variableId,name:i.name}),this.#L.set(i.variableId,i),this.#j.has(i.variableId)||(this.#j.set(i.variableId,""),n.push({id:i.variableId,value:""}));if(!this.#n.disableVariableValidation){const e=new Set(this.#L.keys());for(const t of this.#j.keys())e.has(t)||(this.#j.delete(t),n.push({id:t,value:void 0}))}this.#_.sendWithNoCb("setVariableDefinitions",{variables:t,newValues:n})}setVariableValues(e){const t=[];for(const[n,i]of Object.entries(e))this.#n.disableVariableValidation?(void 0===i?this.#j.delete(n):this.#j.set(n,i),t.push({id:n,value:i})):this.#L.has(n)?(this.#j.set(n,i??""),t.push({id:n,value:i??""})):t.push({id:n,value:void 0});this.#_.sendWithNoCb("setVariableValues",{newValues:t})}getVariableValue(e){return this.#j.get(e)}async parseVariablesInString(e){const t=this.#Q.parseVariablesContext;return t&&this.log("debug",`parseVariablesInString called while in: ${t}. You should use the parseVariablesInString provided to the callback instead`),(await this.#_.sendWithCb("parseVariablesInString",{text:e,controlId:void 0,actionInstanceId:void 0,feedbackInstanceId:void 0})).text}checkFeedbacks(...e){this.#Q.checkFeedbacks(e)}checkFeedbacksById(...e){this.#Q.checkFeedbacksById(e)}_getAllActions(){return this.#E._getAllActions()}subscribeActions(...e){this.#E.subscribeActions(e)}unsubscribeActions(...e){this.#E.unsubscribeActions(e)}_getAllFeedbacks(){return this.#Q._getAllFeedbacks()}subscribeFeedbacks(...e){this.#Q.subscribeFeedbacks(e)}unsubscribeFeedbacks(...e){this.#Q.unsubscribeFeedbacks(e)}recordAction(e,t){if(!this.#x)throw new Error("Not currently recording actions");this.#_.sendWithNoCb("recordAction",{uniquenessId:t??null,actionId:e.actionId,options:e.options})}setCustomVariableValue(e,t){this.#_.sendWithNoCb("setCustomVariable",{customVariableId:e,value:t})}oscSend(e,t,n,i){this.#_.sendWithNoCb("send-osc",(0,s.literal)({host:e,port:t,path:n,args:i}))}updateStatus(e,t){this.#_.sendWithNoCb("set-status",(0,s.literal)({status:e,message:t??null}))}log(e,t){this.#_.sendWithNoCb("log-message",(0,s.literal)({level:e,message:t}))}}},7386:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},1400:(e,t)=>{"use strict";var n,i;Object.defineProperty(t,"__esModule",{value:!0}),t.Regex=t.InstanceStatus=void 0,(i=t.InstanceStatus||(t.InstanceStatus={})).Ok="ok",i.Connecting="connecting",i.Disconnected="disconnected",i.ConnectionFailure="connection_failure",i.BadConfig="bad_config",i.UnknownError="unknown_error",i.UnknownWarning="unknown_warning",(n=t.Regex||(t.Regex={})).IP="/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/",n.HOSTNAME="/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/",n.BOOLEAN="/^(true|false|0|1)$/i",n.PORT="/^([1-9]|[1-8][0-9]|9[0-9]|[1-8][0-9]{2}|9[0-8][0-9]|99[0-9]|[1-8][0-9]{3}|9[0-8][0-9]{2}|99[0-8][0-9]|999[0-9]|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-4])$/",n.MAC_ADDRESS="/^(?:[a-fA-F0-9]{2}:){5}([a-fA-F0-9]{2})$/",n.PERCENT="/^(100|[0-9]|[0-9][0-9])$/",n.FLOAT="/^([0-9]*\\.)?[0-9]+$/",n.SIGNED_FLOAT="/^[+-]?([0-9]*\\.)?[0-9]+$/",n.FLOAT_OR_INT="/^([0-9]+)(\\.[0-9]+)?$/",n.NUMBER="/^\\d+$/",n.SIGNED_NUMBER="/^[+-]?\\d+$/",n.SOMETHING="/^.+$/",n.TIMECODE="/^(0*[0-9]|1[0-9]|2[0-4]):(0*[0-9]|[1-5][0-9]|60):(0*[0-9]|[1-5][0-9]|60):(0*[0-9]|[12][0-9]|30)$/"},8983:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},8104:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},2018:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=n(1635);i.__exportStar(n(3730),t),i.__exportStar(n(1649),t),i.__exportStar(n(7386),t),i.__exportStar(n(1400),t),i.__exportStar(n(8983),t),i.__exportStar(n(8104),t),i.__exportStar(n(3258),t),i.__exportStar(n(131),t),i.__exportStar(n(3371),t),i.__exportStar(n(9786),t),i.__exportStar(n(6132),t)},3258:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},131:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},3371:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},9786:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CreateUseBuiltinInvertForFeedbacksUpgradeScript=t.CreateConvertToBooleanFeedbackUpgradeScript=t.EmptyUpgradeScript=void 0,t.EmptyUpgradeScript=()=>({updatedConfig:null,updatedActions:[],updatedFeedbacks:[]}),t.CreateConvertToBooleanFeedbackUpgradeScript=function(e){return(t,n)=>{const i=[];for(const t of n.feedbacks){let n=e[t.feedbackId];if(!0===n&&(n={bg:"bgcolor",bgcolor:"bgcolor",fg:"color",color:"color",png64:"png64",png:"png64"}),n){t.style||(t.style={});for(const[e,s]of Object.entries(n))void 0!==t.options[e]&&(t.style[s]=t.options[e],delete t.options[e],i.push(t))}}return{updatedConfig:null,updatedActions:[],updatedFeedbacks:i}}},t.CreateUseBuiltinInvertForFeedbacksUpgradeScript=function(e){return(t,n)=>{const i=[];for(const t of n.feedbacks){const n=e[t.feedbackId];if("string"!=typeof n)continue;const s=t.options[n];void 0!==s&&(delete t.options[n],t.isInverted="true"===s||!0===s||Number(s)>0,i.push(t))}return{updatedConfig:null,updatedActions:[],updatedFeedbacks:i}}}},6132:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},360:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.splitHex=t.splitHsv=t.splitHsl=t.splitRgb=t.combineRgb=t.assertNever=t.literal=void 0;const i=n(6284);function s(e){if("number"==typeof e)return e>16777215?{r:e>>16&255,g:e>>8&255,b:255&e,a:(255-(e>>24&255))/255}:{r:e>>16&255,g:e>>8&255,b:255&e,a:1};if("string"==typeof e&&(0,i.colord)(e).isValid()){const t=(0,i.colord)(e).toRgb();return{r:t.r,g:t.g,b:t.b,a:t.a}}return{r:0,g:0,b:0,a:1}}t.literal=function(e){return e},t.assertNever=function(e){},t.combineRgb=function(e,t,n,i){let s=(255&e)<<16|(255&t)<<8|255&n;return i&&i>=0&&i<1&&(s+=16777216*Math.round(255*(1-i))),s},t.splitRgb=s,t.splitHsl=function(e){const t=s(e);return(0,i.colord)(`rgba(${t.r}, ${t.g}, ${t.b}, ${t.a})`).toHsl()},t.splitHsv=function(e){const t=s(e);return(0,i.colord)(`rgba(${t.r}, ${t.g}, ${t.b}, ${t.a})`).toHsv()},t.splitHex=function(e){const t=s(e);return(0,i.colord)(`rgba(${t.r}, ${t.g}, ${t.b}, ${t.a})`).toHex()}},7281:(e,t,n)=>{"use strict";e.exports=a,e.exports.default=a;const i={$schema:"http://json-schema.org/draft-07/schema#",type:"object",title:"ModuleManifest",properties:{$schema:{type:"string"},id:{type:"string",description:"Unique identifier for the module"},name:{type:"string",description:"Name of the module"},shortname:{type:"string"},description:{type:"string",description:"Description of the module "},version:{type:"string",description:"Current version of the module"},license:{type:"string",description:"SPDX identifier for license of the module"},repository:{type:"string",description:"URL to the source repository"},bugs:{type:"string",description:"URL to bug tracker"},maintainers:{type:"array",description:"List of active maintiners",uniqueItems:!0,items:{type:"object",title:"ModuleManifestMaintainer",properties:{name:{type:"string"},email:{type:"string"},github:{type:"string"}},required:["name"]}},legacyIds:{type:"array",description:"If the module had a different unique identifier previously, then specify it here",uniqueItems:!0,items:{type:"string"}},runtime:{type:"object",title:"ModuleManifestRuntime",description:"Information on how to execute the module",properties:{type:{type:"string",description:"Type of the module. Must be: node18"},api:{type:"string",description:"Which host-api does it use. In the future alternate options will be allowed",enum:["nodejs-ipc"]},apiVersion:{type:"string",description:"The version of the host-api used"},entrypoint:{type:"string",description:"Entrypoint to pass to the runtime. eg index.js"}},required:["type","api","apiVersion","entrypoint"]},manufacturer:{type:"string"},products:{type:"array",uniqueItems:!0,items:{type:"string"}},keywords:{type:"array",uniqueItems:!0,items:{type:"string"}},bonjourQueries:{type:"object",description:"If the device or software for your module supports bonjour announcements, Companion will offer an easy way to watch for these announcements.\nEach query you define must have a matching config field of type 'bonjour-device' with the same name",patternProperties:{"":{type:"object",title:"ModuleBonjourQuery",description:"",properties:{type:{type:"string"},protocol:{type:"string",enum:["tcp","udp"]},txt:{type:"object",description:"Match on any txt values returned in the query. This is useful to filter out devices of the same 'type' that are not supported",patternProperties:{"":{type:"string"}},additionalProperties:!1}},required:["type","protocol"],additionalProperties:!1}},additionalProperties:!1}},additionalProperties:!1,required:["id","name","shortname","description","version","license","repository","bugs","maintainers","legacyIds","runtime","manufacturer","products","keywords"]},s=Object.prototype.hasOwnProperty,o=n(7169).A,r=new RegExp("","u");function a(e,{instancePath:t="",parentData:n,parentDataProperty:c,rootData:l=e}={}){if(!e||"object"!=typeof e||Array.isArray(e))return a.errors=[{instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;{let n;if(void 0===e.id&&(n="id")||void 0===e.name&&(n="name")||void 0===e.shortname&&(n="shortname")||void 0===e.description&&(n="description")||void 0===e.version&&(n="version")||void 0===e.license&&(n="license")||void 0===e.repository&&(n="repository")||void 0===e.bugs&&(n="bugs")||void 0===e.maintainers&&(n="maintainers")||void 0===e.legacyIds&&(n="legacyIds")||void 0===e.runtime&&(n="runtime")||void 0===e.manufacturer&&(n="manufacturer")||void 0===e.products&&(n="products")||void 0===e.keywords&&(n="keywords"))return a.errors=[{instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:n},message:"must have required property '"+n+"'"}],!1;{const n=0;for(const n in e)if(!s.call(i.properties,n))return a.errors=[{instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:n},message:"must NOT have additional properties"}],!1;if(0===n){if(void 0!==e.$schema){const n=0;if("string"!=typeof e.$schema)return a.errors=[{instancePath:t+"/$schema",schemaPath:"#/properties/%24schema/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var g=0===n}else g=!0;if(g){if(void 0!==e.id){const n=0;if("string"!=typeof e.id)return a.errors=[{instancePath:t+"/id",schemaPath:"#/properties/id/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.name){const n=0;if("string"!=typeof e.name)return a.errors=[{instancePath:t+"/name",schemaPath:"#/properties/name/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.shortname){const n=0;if("string"!=typeof e.shortname)return a.errors=[{instancePath:t+"/shortname",schemaPath:"#/properties/shortname/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.description){const n=0;if("string"!=typeof e.description)return a.errors=[{instancePath:t+"/description",schemaPath:"#/properties/description/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.version){const n=0;if("string"!=typeof e.version)return a.errors=[{instancePath:t+"/version",schemaPath:"#/properties/version/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.license){const n=0;if("string"!=typeof e.license)return a.errors=[{instancePath:t+"/license",schemaPath:"#/properties/license/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.repository){const n=0;if("string"!=typeof e.repository)return a.errors=[{instancePath:t+"/repository",schemaPath:"#/properties/repository/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.bugs){const n=0;if("string"!=typeof e.bugs)return a.errors=[{instancePath:t+"/bugs",schemaPath:"#/properties/bugs/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.maintainers){let n=e.maintainers;const i=0;if(0===i){if(!Array.isArray(n))return a.errors=[{instancePath:t+"/maintainers",schemaPath:"#/properties/maintainers/type",keyword:"type",params:{type:"array"},message:"must be array"}],!1;{var d=!0;const e=n.length;for(let i=0;i1)for(;i--;)for(e=i;e--;)if(o(n[i],n[e]))return a.errors=[{instancePath:t+"/maintainers",schemaPath:"#/properties/maintainers/uniqueItems",keyword:"uniqueItems",params:{i,j:e},message:"must NOT have duplicate items (items ## "+e+" and "+i+" are identical)"}],!1}}}g=0===i}else g=!0;if(g){if(void 0!==e.legacyIds){let n=e.legacyIds;const i=0;if(0===i){if(!Array.isArray(n))return a.errors=[{instancePath:t+"/legacyIds",schemaPath:"#/properties/legacyIds/type",keyword:"type",params:{type:"array"},message:"must be array"}],!1;{var b=!0;const e=n.length;for(let i=0;i1){const s={};for(;i--;){let o=n[i];if("string"==typeof o){if("number"==typeof s[o])return e=s[o],a.errors=[{instancePath:t+"/legacyIds",schemaPath:"#/properties/legacyIds/uniqueItems",keyword:"uniqueItems",params:{i,j:e},message:"must NOT have duplicate items (items ## "+e+" and "+i+" are identical)"}],!1;s[o]=i}}}}}}g=0===i}else g=!0;if(g){if(void 0!==e.runtime){let n=e.runtime;const s=0;if(0===s){if(!n||"object"!=typeof n||Array.isArray(n))return a.errors=[{instancePath:t+"/runtime",schemaPath:"#/properties/runtime/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;{let e;if(void 0===n.type&&(e="type")||void 0===n.api&&(e="api")||void 0===n.apiVersion&&(e="apiVersion")||void 0===n.entrypoint&&(e="entrypoint"))return a.errors=[{instancePath:t+"/runtime",schemaPath:"#/properties/runtime/required",keyword:"required",params:{missingProperty:e},message:"must have required property '"+e+"'"}],!1;if(void 0!==n.type){const e=0;if("string"!=typeof n.type)return a.errors=[{instancePath:t+"/runtime/type",schemaPath:"#/properties/runtime/properties/type/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var I=0===e}else I=!0;if(I){if(void 0!==n.api){let e=n.api;const s=0;if("string"!=typeof e)return a.errors=[{instancePath:t+"/runtime/api",schemaPath:"#/properties/runtime/properties/api/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;if("nodejs-ipc"!==e)return a.errors=[{instancePath:t+"/runtime/api",schemaPath:"#/properties/runtime/properties/api/enum",keyword:"enum",params:{allowedValues:i.properties.runtime.properties.api.enum},message:"must be equal to one of the allowed values"}],!1;I=0===s}else I=!0;if(I){if(void 0!==n.apiVersion){const e=0;if("string"!=typeof n.apiVersion)return a.errors=[{instancePath:t+"/runtime/apiVersion",schemaPath:"#/properties/runtime/properties/apiVersion/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;I=0===e}else I=!0;if(I)if(void 0!==n.entrypoint){const e=0;if("string"!=typeof n.entrypoint)return a.errors=[{instancePath:t+"/runtime/entrypoint",schemaPath:"#/properties/runtime/properties/entrypoint/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;I=0===e}else I=!0}}}}g=0===s}else g=!0;if(g){if(void 0!==e.manufacturer){const n=0;if("string"!=typeof e.manufacturer)return a.errors=[{instancePath:t+"/manufacturer",schemaPath:"#/properties/manufacturer/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.products){let n=e.products;const i=0;if(0===i){if(!Array.isArray(n))return a.errors=[{instancePath:t+"/products",schemaPath:"#/properties/products/type",keyword:"type",params:{type:"array"},message:"must be array"}],!1;{var p=!0;const e=n.length;for(let i=0;i1){const s={};for(;i--;){let o=n[i];if("string"==typeof o){if("number"==typeof s[o])return e=s[o],a.errors=[{instancePath:t+"/products",schemaPath:"#/properties/products/uniqueItems",keyword:"uniqueItems",params:{i,j:e},message:"must NOT have duplicate items (items ## "+e+" and "+i+" are identical)"}],!1;s[o]=i}}}}}}g=0===i}else g=!0;if(g){if(void 0!==e.keywords){let n=e.keywords;const i=0;if(0===i){if(!Array.isArray(n))return a.errors=[{instancePath:t+"/keywords",schemaPath:"#/properties/keywords/type",keyword:"type",params:{type:"array"},message:"must be array"}],!1;{var C=!0;const e=n.length;for(let i=0;i1){const s={};for(;i--;){let o=n[i];if("string"==typeof o){if("number"==typeof s[o])return e=s[o],a.errors=[{instancePath:t+"/keywords",schemaPath:"#/properties/keywords/uniqueItems",keyword:"uniqueItems",params:{i,j:e},message:"must NOT have duplicate items (items ## "+e+" and "+i+" are identical)"}],!1;s[o]=i}}}}}}g=0===i}else g=!0;if(g)if(void 0!==e.bonjourQueries){let n=e.bonjourQueries;const s=0;if(0===s){if(!n||"object"!=typeof n||Array.isArray(n))return a.errors=[{instancePath:t+"/bonjourQueries",schemaPath:"#/properties/bonjourQueries/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;{const e=0;for(const e in n)if(!r.test(e))return a.errors=[{instancePath:t+"/bonjourQueries",schemaPath:"#/properties/bonjourQueries/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:e},message:"must NOT have additional properties"}],!1;if(0===e)for(const e in n)if(r.test(e)){let s=n[e];const o=0;if(0===o){if(!s||"object"!=typeof s||Array.isArray(s))return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/bonjourQueries/patternProperties//type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;{let n;if(void 0===s.type&&(n="type")||void 0===s.protocol&&(n="protocol"))return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/bonjourQueries/patternProperties//required",keyword:"required",params:{missingProperty:n},message:"must have required property '"+n+"'"}],!1;{const n=0;for(const n in s)if("type"!==n&&"protocol"!==n&&"txt"!==n)return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/bonjourQueries/patternProperties//additionalProperties",keyword:"additionalProperties",params:{additionalProperty:n},message:"must NOT have additional properties"}],!1;if(0===n){if(void 0!==s.type){const n=0;if("string"!=typeof s.type)return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1")+"/type",schemaPath:"#/properties/bonjourQueries/patternProperties//properties/type/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var h=0===n}else h=!0;if(h){if(void 0!==s.protocol){let n=s.protocol;const o=0;if("string"!=typeof n)return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1")+"/protocol",schemaPath:"#/properties/bonjourQueries/patternProperties//properties/protocol/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;if("tcp"!==n&&"udp"!==n)return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1")+"/protocol",schemaPath:"#/properties/bonjourQueries/patternProperties//properties/protocol/enum",keyword:"enum",params:{allowedValues:i.properties.bonjourQueries.patternProperties[""].properties.protocol.enum},message:"must be equal to one of the allowed values"}],!1;h=0===o}else h=!0;if(h)if(void 0!==s.txt){let n=s.txt;const i=0;if(0===i){if(!n||"object"!=typeof n||Array.isArray(n))return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1")+"/txt",schemaPath:"#/properties/bonjourQueries/patternProperties//properties/txt/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;{const i=0;for(const i in n)if(!r.test(i))return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1")+"/txt",schemaPath:"#/properties/bonjourQueries/patternProperties//properties/txt/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:i},message:"must NOT have additional properties"}],!1;if(0===i)for(const i in n)if(r.test(i)){const s=0;if("string"!=typeof n[i])return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1")+"/txt/"+i.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/bonjourQueries/patternProperties//properties/txt/patternProperties//type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;if(0!==s)break}}}h=0===i}else h=!0}}}}}if(0!==o)break}}}g=0===s}else g=!0}}}}}}}}}}}}}}}}}return a.errors=null,!0}},7e3:(e,t,n)=>{"use strict";const i=n(4865);e.exports=(e,t={})=>{if("function"!=typeof e)throw new TypeError(`Expected the first argument to be a function, got \`${typeof e}\``);const{wait:n=0,maxWait:s=0,before:o=!1,after:r=!0}=t;if(!o&&!r)throw new Error("Both `before` and `after` are false, function wouldn't be called.");let a,c,l;const g=function(...t){const i=this,g=o&&!a;return clearTimeout(a),a=setTimeout((()=>{a=void 0,c&&(clearTimeout(c),c=void 0),r&&(l=e.apply(i,t))}),n),s>0&&!c&&r&&(c=setTimeout((()=>{c=void 0,a&&(clearTimeout(a),a=void 0),l=e.apply(i,t)}),s)),g&&(l=e.apply(i,t)),l};return i(g,e),g.cancel=()=>{a&&(clearTimeout(a),a=void 0),c&&(clearTimeout(c),c=void 0)},g}},8515:(e,t,n)=>{"use strict";var i=n(6278);const s=[{id:"xvs-9000",label:"XVS 9000/8000/7000/6000"},{id:"xvs-g1",label:"XVS-G1"},{id:"mls-x1",label:"MLS-X1"}],o=[{id:"pp",label:"P/P",address:0},{id:"me1",label:"M/E 1",address:1},{id:"me2",label:"M/E 2",address:2},{id:"me3",label:"M/E 3",address:3},{id:"me4",label:"M/E 4",address:4},{id:"me5",label:"M/E 5",address:5}],r=[{id:"fm1",label:"FM1",address:20},{id:"fm2",label:"FM2",address:21}],a=[{id:"aux1",label:"Aux 1",address:48},{id:"aux2",label:"Aux 2",address:49},{id:"aux3",label:"Aux 3",address:50},{id:"aux4",label:"Aux 4",address:51},{id:"aux5",label:"Aux 5",address:52},{id:"aux6",label:"Aux 6",address:53},{id:"aux7",label:"Aux 7",address:54},{id:"aux8",label:"Aux 8",address:55},{id:"aux9",label:"Aux 9",address:56},{id:"aux10",label:"Aux 10",address:57},{id:"aux11",label:"Aux 11",address:58},{id:"aux12",label:"Aux 12",address:59},{id:"aux13",label:"Aux 13",address:60},{id:"aux14",label:"Aux 14",address:61},{id:"aux15",label:"Aux 15",address:62},{id:"aux16",label:"Aux 16",address:64},{id:"aux17",label:"Aux 17",address:65},{id:"aux18",label:"Aux 18",address:66},{id:"aux19",label:"Aux 19",address:67},{id:"aux20",label:"Aux 20",address:68},{id:"aux21",label:"Aux 21",address:69},{id:"aux22",label:"Aux 22",address:70},{id:"aux23",label:"Aux 23",address:71},{id:"aux24",label:"Aux 24",address:72},{id:"aux25",label:"Aux 25",address:73},{id:"aux26",label:"Aux 26",address:74},{id:"aux27",label:"Aux 27",address:75},{id:"aux28",label:"Aux 28",address:76},{id:"aux29",label:"Aux 29",address:77},{id:"aux30",label:"Aux 30",address:78},{id:"aux31",label:"Aux 31",address:79},{id:"aux32",label:"Aux 32",address:80},{id:"aux33",label:"Aux 33",address:81},{id:"aux34",label:"Aux 34",address:82},{id:"aux35",label:"Aux 35",address:83},{id:"aux36",label:"Aux 36",address:84},{id:"aux37",label:"Aux 37",address:85},{id:"aux38",label:"Aux 38",address:86},{id:"aux39",label:"Aux 39",address:87},{id:"aux40",label:"Aux 40",address:88},{id:"aux41",label:"Aux 41",address:89},{id:"aux42",label:"Aux 42",address:90},{id:"aux43",label:"Aux 43",address:91},{id:"aux44",label:"Aux 44",address:92},{id:"aux45",label:"Aux 45",address:93},{id:"aux46",label:"Aux 46",address:94},{id:"aux47",label:"Aux 47",address:95},{id:"aux48",label:"Aux 48",address:96},{id:"edit_pvw",label:"EDIT PVW",address:63}],c=[{id:"mp2_main",label:"MP2 Main, or Standard Config",writeByte:240,readByte:112},{id:"mp2_sub",label:"MP2 Sub",writeByte:241,readByte:113},{id:"mp2_both",label:"MP2 Main/Sub (Both)",writeByte:242,readByte:114}],l={"xvs-9000":[{id:"pgm",label:"PGM",readByte:64,writeByte:192},{id:"pst",label:"PST",readByte:65,writeByte:193},{id:"key1_fill",label:"Key 1 Fill",readByte:71,writeByte:199},{id:"key1_source",label:"Key 1 Source",readByte:72,writeByte:200},{id:"key2_fill",label:"Key 2 Fill",readByte:77,writeByte:205},{id:"key2_source",label:"Key 2 Source",readByte:78,writeByte:206},{id:"key3_fill",label:"Key 3 Fill",readByte:73,writeByte:201},{id:"key3_source",label:"Key 3 Source",readByte:74,writeByte:202},{id:"key4_fill",label:"Key 4 Fill",readByte:75,writeByte:203},{id:"key4_source",label:"Key 4 Source",readByte:76,writeByte:204},{id:"key5_fill",label:"Key 5 Fill",readByte:80,writeByte:208},{id:"key5_source",label:"Key 5 Source",readByte:81,writeByte:209},{id:"key6_fill",label:"Key 6 Fill",readByte:86,writeByte:214},{id:"key6_source",label:"Key 6 Source",readByte:87,writeByte:215},{id:"key7_fill",label:"Key 7 Fill",readByte:82,writeByte:210},{id:"key7_source",label:"Key 7 Source",readByte:83,writeByte:211},{id:"key8_fill",label:"Key 8 Fill",readByte:84,writeByte:212},{id:"key8_source",label:"Key 8 Source",readByte:85,writeByte:213},{id:"util1",label:"Utility 1",readByte:79,writeByte:207},{id:"util2",label:"Utility 2 / MP2 Sub BKGD A",readByte:66,writeByte:194},{id:"util3",label:"Utility 3 / MP2 Sub BKGD B",readByte:70,writeByte:198},{id:"dme_v",label:"DME V",readByte:67,writeByte:195},{id:"dme_k",label:"DME K",readByte:68,writeByte:196},{id:"dme_ext",label:"DME EXT",readByte:69,writeByte:197}],"xvs-g1":[{id:"pgm",label:"PGM",readByte:64,writeByte:192},{id:"pst",label:"PST",readByte:65,writeByte:193},{id:"key1_fill",label:"Key 1 Fill",readByte:71,writeByte:199},{id:"key1_source",label:"Key 1 Source",readByte:72,writeByte:200},{id:"key2_fill",label:"Key 2 Fill",readByte:77,writeByte:205},{id:"key2_source",label:"Key 2 Source",readByte:78,writeByte:206},{id:"key3_fill",label:"Key 3 Fill",readByte:73,writeByte:201},{id:"key3_source",label:"Key 3 Source",readByte:74,writeByte:202},{id:"key4_fill",label:"Key 4 Fill",readByte:75,writeByte:203},{id:"key4_source",label:"Key 4 Source",readByte:76,writeByte:204},{id:"key5_fill",label:"Key 5 Fill",readByte:80,writeByte:208},{id:"key5_source",label:"Key 5 Source",readByte:81,writeByte:209},{id:"key6_fill",label:"Key 6 Fill",readByte:86,writeByte:214},{id:"key6_source",label:"Key 6 Source",readByte:87,writeByte:215},{id:"key7_fill",label:"Key 7 Fill",readByte:82,writeByte:210},{id:"key7_source",label:"Key 7 Source",readByte:83,writeByte:211},{id:"key8_fill",label:"Key 8 Fill",readByte:84,writeByte:212},{id:"key8_source",label:"Key 8 Source",readByte:85,writeByte:213},{id:"util1",label:"Utility 1",readByte:79,writeByte:207},{id:"util2",label:"Utility 2",readByte:66,writeByte:194},{id:"mp2_sub_bkgd_a",label:"MP2 Sub BKGD A",readByte:88,writeByte:216},{id:"mp2_sub_bkgd_b",label:"MP2 Sub BKGD B",readByte:89,writeByte:217},{id:"mp2_sub_util2",label:"MP2 Sub UTILITY 2",readByte:70,writeByte:198},{id:"dme_v",label:"DME V",readByte:67,writeByte:195},{id:"dme_k",label:"DME K",readByte:68,writeByte:196},{id:"dme_ext",label:"DME EXT",readByte:69,writeByte:197}],"mls-x1":[{id:"pgm",label:"PGM",readByte:64,writeByte:192},{id:"pst",label:"PST",readByte:65,writeByte:193},{id:"key1_fill",label:"Key 1 Fill",readByte:71,writeByte:199},{id:"key1_source",label:"Key 1 Source",readByte:72,writeByte:200},{id:"key2_fill",label:"Key 2 Fill",readByte:77,writeByte:205},{id:"key2_source",label:"Key 2 Source",readByte:78,writeByte:206},{id:"key3_fill",label:"Key 3 Fill",readByte:73,writeByte:201},{id:"key3_source",label:"Key 3 Source",readByte:74,writeByte:202},{id:"key4_fill",label:"Key 4 Fill",readByte:75,writeByte:203},{id:"key4_source",label:"Key 4 Source",readByte:76,writeByte:204},{id:"key5_fill",label:"Key 5 Fill",readByte:80,writeByte:208},{id:"key5_source",label:"Key 5 Source",readByte:81,writeByte:209},{id:"key6_fill",label:"Key 6 Fill",readByte:86,writeByte:214},{id:"key6_source",label:"Key 6 Source",readByte:87,writeByte:215},{id:"key7_fill",label:"Key 7 Fill",readByte:82,writeByte:210},{id:"key7_source",label:"Key 7 Source",readByte:83,writeByte:211},{id:"key8_fill",label:"Key 8 Fill",readByte:84,writeByte:212},{id:"key8_source",label:"Key 8 Source",readByte:85,writeByte:213},{id:"util1",label:"Utility 1",readByte:79,writeByte:207},{id:"util2",label:"Utility 2",readByte:66,writeByte:194},{id:"mp2_sub_bkgd_a",label:"MP2 Sub BKGD A",readByte:88,writeByte:216},{id:"mp2_sub_bkgd_b",label:"MP2 Sub BKGD B",readByte:89,writeByte:217},{id:"mp2_sub_util2",label:"MP2 Sub UTILITY 2",readByte:70,writeByte:198},{id:"dme_v",label:"DME V",readByte:67,writeByte:195},{id:"dme_k",label:"DME K",readByte:68,writeByte:196},{id:"dme_ext",label:"DME EXT",readByte:69,writeByte:197}]},g=[{id:"key1",label:"Key 1",address:16},{id:"key2",label:"Key 2",address:48},{id:"key3",label:"Key 3",address:80},{id:"key4",label:"Key 4",address:112},{id:"key5",label:"Key 5",address:144},{id:"key6",label:"Key 6",address:176},{id:"key7",label:"Key 7",address:208},{id:"key8",label:"Key 8",address:240}],d={"xvs-9000":[{id:1,label:"Primary 1",byte1:0,byte2:1},{id:2,label:"Primary 2",byte1:0,byte2:2},{id:3,label:"Primary 3",byte1:0,byte2:3},{id:4,label:"Primary 4",byte1:0,byte2:4},{id:5,label:"Primary 5",byte1:0,byte2:5},{id:6,label:"Primary 6",byte1:0,byte2:6},{id:7,label:"Primary 7",byte1:0,byte2:7},{id:8,label:"Primary 8",byte1:0,byte2:8},{id:9,label:"Primary 9",byte1:0,byte2:9},{id:10,label:"Primary 10",byte1:0,byte2:10},{id:11,label:"Primary 11",byte1:0,byte2:11},{id:12,label:"Primary 12",byte1:0,byte2:12},{id:13,label:"Primary 13",byte1:0,byte2:13},{id:14,label:"Primary 14",byte1:0,byte2:14},{id:15,label:"Primary 15",byte1:0,byte2:15},{id:16,label:"Primary 16",byte1:0,byte2:16},{id:17,label:"Primary 17",byte1:0,byte2:17},{id:18,label:"Primary 18",byte1:0,byte2:18},{id:19,label:"Primary 19",byte1:0,byte2:19},{id:20,label:"Primary 20",byte1:0,byte2:20},{id:21,label:"Primary 21",byte1:0,byte2:21},{id:22,label:"Primary 22",byte1:0,byte2:22},{id:23,label:"Primary 23",byte1:0,byte2:23},{id:24,label:"Primary 24",byte1:0,byte2:24},{id:25,label:"Primary 25",byte1:0,byte2:25},{id:26,label:"Primary 26",byte1:0,byte2:26},{id:27,label:"Primary 27",byte1:0,byte2:27},{id:28,label:"Primary 28",byte1:0,byte2:28},{id:29,label:"Primary 29",byte1:0,byte2:29},{id:30,label:"Primary 30",byte1:0,byte2:30},{id:31,label:"Primary 31",byte1:0,byte2:31},{id:32,label:"Primary 32",byte1:0,byte2:32},{id:33,label:"Primary 33",byte1:0,byte2:33},{id:34,label:"Primary 34",byte1:0,byte2:34},{id:35,label:"Primary 35",byte1:0,byte2:35},{id:36,label:"Primary 36",byte1:0,byte2:36},{id:37,label:"Primary 37",byte1:0,byte2:37},{id:38,label:"Primary 38",byte1:0,byte2:38},{id:39,label:"Primary 39",byte1:0,byte2:39},{id:40,label:"Primary 40",byte1:0,byte2:40},{id:41,label:"Primary 41",byte1:0,byte2:41},{id:42,label:"Primary 42",byte1:0,byte2:42},{id:43,label:"Primary 43",byte1:0,byte2:43},{id:44,label:"Primary 44",byte1:0,byte2:44},{id:45,label:"Primary 45",byte1:0,byte2:45},{id:46,label:"Primary 46",byte1:0,byte2:46},{id:47,label:"Primary 47",byte1:0,byte2:47},{id:48,label:"Primary 48",byte1:0,byte2:48},{id:49,label:"Primary 49",byte1:0,byte2:49},{id:50,label:"Primary 50",byte1:0,byte2:50},{id:51,label:"Primary 51",byte1:0,byte2:51},{id:52,label:"Primary 52",byte1:0,byte2:52},{id:53,label:"Primary 53",byte1:0,byte2:53},{id:54,label:"Primary 54",byte1:0,byte2:54},{id:55,label:"Primary 55",byte1:0,byte2:55},{id:56,label:"Primary 56",byte1:0,byte2:56},{id:57,label:"Primary 57",byte1:0,byte2:57},{id:58,label:"Primary 58",byte1:0,byte2:58},{id:59,label:"Primary 59",byte1:0,byte2:59},{id:60,label:"Primary 60",byte1:0,byte2:60},{id:61,label:"Primary 61",byte1:0,byte2:61},{id:62,label:"Primary 62",byte1:0,byte2:62},{id:63,label:"Primary 63",byte1:0,byte2:63},{id:64,label:"Primary 64",byte1:0,byte2:64},{id:65,label:"Primary 65",byte1:0,byte2:65},{id:66,label:"Primary 66",byte1:0,byte2:66},{id:67,label:"Primary 67",byte1:0,byte2:67},{id:68,label:"Primary 68",byte1:0,byte2:68},{id:69,label:"Primary 69",byte1:0,byte2:69},{id:70,label:"Primary 70",byte1:0,byte2:70},{id:71,label:"Primary 71",byte1:0,byte2:71},{id:72,label:"Primary 72",byte1:0,byte2:72},{id:73,label:"Primary 73",byte1:0,byte2:73},{id:74,label:"Primary 74",byte1:0,byte2:74},{id:75,label:"Primary 75",byte1:0,byte2:75},{id:76,label:"Primary 76",byte1:0,byte2:76},{id:77,label:"Primary 77",byte1:0,byte2:77},{id:78,label:"Primary 78",byte1:0,byte2:78},{id:79,label:"Primary 79",byte1:0,byte2:79},{id:80,label:"Primary 80",byte1:0,byte2:80},{id:81,label:"Primary 81",byte1:0,byte2:81},{id:82,label:"Primary 82",byte1:0,byte2:82},{id:83,label:"Primary 83",byte1:0,byte2:83},{id:84,label:"Primary 84",byte1:0,byte2:84},{id:85,label:"Primary 85",byte1:0,byte2:85},{id:86,label:"Primary 86",byte1:0,byte2:86},{id:87,label:"Primary 87",byte1:0,byte2:87},{id:88,label:"Primary 88",byte1:0,byte2:88},{id:89,label:"Primary 89",byte1:0,byte2:89},{id:90,label:"Primary 90",byte1:0,byte2:90},{id:91,label:"Primary 91",byte1:0,byte2:91},{id:92,label:"Primary 92",byte1:0,byte2:92},{id:93,label:"Primary 93",byte1:0,byte2:93},{id:94,label:"Primary 94",byte1:0,byte2:94},{id:95,label:"Primary 95",byte1:0,byte2:95},{id:96,label:"Primary 96",byte1:0,byte2:96},{id:97,label:"Primary 97",byte1:0,byte2:97},{id:98,label:"Primary 98",byte1:0,byte2:98},{id:99,label:"Primary 99",byte1:0,byte2:99},{id:100,label:"Primary 100",byte1:0,byte2:100},{id:101,label:"Primary 101",byte1:0,byte2:101},{id:102,label:"Primary 102",byte1:0,byte2:102},{id:103,label:"Primary 103",byte1:0,byte2:103},{id:104,label:"Primary 104",byte1:0,byte2:104},{id:105,label:"Primary 105",byte1:0,byte2:105},{id:106,label:"Primary 106",byte1:0,byte2:106},{id:107,label:"Primary 107",byte1:0,byte2:107},{id:108,label:"Primary 108",byte1:0,byte2:108},{id:109,label:"Primary 109",byte1:0,byte2:109},{id:110,label:"Primary 110",byte1:0,byte2:110},{id:111,label:"Primary 111",byte1:0,byte2:111},{id:112,label:"Primary 112",byte1:0,byte2:112},{id:113,label:"Primary 113",byte1:0,byte2:113},{id:114,label:"Primary 114",byte1:0,byte2:114},{id:115,label:"Primary 115",byte1:0,byte2:115},{id:116,label:"Primary 116",byte1:0,byte2:116},{id:117,label:"Primary 117",byte1:0,byte2:117},{id:118,label:"Primary 118",byte1:0,byte2:118},{id:119,label:"Primary 119",byte1:0,byte2:119},{id:120,label:"Primary 120",byte1:0,byte2:120},{id:121,label:"Primary 121",byte1:0,byte2:121},{id:122,label:"Primary 122",byte1:0,byte2:122},{id:123,label:"Primary 123",byte1:0,byte2:123},{id:124,label:"Primary 124",byte1:0,byte2:124},{id:125,label:"Primary 125",byte1:0,byte2:125},{id:126,label:"Primary 126",byte1:0,byte2:126},{id:127,label:"Primary 127",byte1:0,byte2:127},{id:128,label:"Primary 128",byte1:0,byte2:128},{id:129,label:"Primary 129",byte1:0,byte2:129},{id:130,label:"Primary 130",byte1:0,byte2:130},{id:131,label:"Primary 131",byte1:0,byte2:131},{id:132,label:"Primary 132",byte1:0,byte2:132},{id:133,label:"Primary 133",byte1:0,byte2:133},{id:134,label:"Primary 134",byte1:0,byte2:134},{id:135,label:"Primary 135",byte1:0,byte2:135},{id:136,label:"Primary 136",byte1:0,byte2:136},{id:137,label:"Primary 137",byte1:0,byte2:137},{id:138,label:"Primary 138",byte1:0,byte2:138},{id:139,label:"Primary 139",byte1:0,byte2:139},{id:140,label:"Primary 140",byte1:0,byte2:140},{id:141,label:"Primary 141",byte1:0,byte2:141},{id:142,label:"Primary 142",byte1:0,byte2:142},{id:143,label:"Primary 143",byte1:0,byte2:143},{id:144,label:"Primary 144",byte1:0,byte2:144},{id:145,label:"Primary 145",byte1:0,byte2:145},{id:146,label:"Primary 146",byte1:0,byte2:146},{id:147,label:"Primary 147",byte1:0,byte2:147},{id:148,label:"Primary 148",byte1:0,byte2:148},{id:149,label:"Primary 149",byte1:0,byte2:149},{id:150,label:"Primary 150",byte1:0,byte2:150},{id:151,label:"Primary 151",byte1:0,byte2:151},{id:152,label:"Primary 152",byte1:0,byte2:152},{id:153,label:"Primary 153",byte1:0,byte2:153},{id:154,label:"Primary 154",byte1:0,byte2:154},{id:155,label:"Primary 155",byte1:0,byte2:155},{id:156,label:"Primary 156",byte1:0,byte2:156},{id:157,label:"Primary 157",byte1:0,byte2:157},{id:158,label:"Primary 158",byte1:0,byte2:158},{id:159,label:"Primary 159",byte1:0,byte2:159},{id:160,label:"Primary 160",byte1:0,byte2:160},{id:165,label:"FC1",byte1:0,byte2:165},{id:166,label:"FC2",byte1:0,byte2:166},{id:167,label:"FC3",byte1:0,byte2:167},{id:168,label:"FC4",byte1:0,byte2:168},{id:169,label:"FC5",byte1:0,byte2:169},{id:170,label:"FC6",byte1:0,byte2:170},{id:171,label:"FC7",byte1:0,byte2:171},{id:172,label:"FC8",byte1:0,byte2:172},{id:173,label:"FC9",byte1:0,byte2:173},{id:174,label:"FC10",byte1:0,byte2:174},{id:175,label:"FC11",byte1:0,byte2:175},{id:176,label:"FC12",byte1:0,byte2:176},{id:177,label:"FC13",byte1:0,byte2:177},{id:178,label:"FC14",byte1:0,byte2:178},{id:179,label:"FC15",byte1:0,byte2:179},{id:180,label:"FC16",byte1:0,byte2:180},{id:181,label:"Black",byte1:0,byte2:181},{id:182,label:"White",byte1:0,byte2:182},{id:183,label:"Color Bkgd 1",byte1:0,byte2:183},{id:184,label:"Color Bkgd1-2",byte1:0,byte2:184},{id:185,label:"Color Bkgd 2",byte1:0,byte2:185},{id:186,label:"Color Bkgd2-2",byte1:0,byte2:186},{id:187,label:"FM1",byte1:0,byte2:187},{id:188,label:"FM2",byte1:0,byte2:188},{id:189,label:"FM3",byte1:0,byte2:189},{id:190,label:"FM4",byte1:0,byte2:190},{id:191,label:"FM5",byte1:0,byte2:191},{id:192,label:"FM6",byte1:0,byte2:192},{id:193,label:"FM7",byte1:0,byte2:193},{id:194,label:"FM8",byte1:0,byte2:194},{id:195,label:"FM9",byte1:0,byte2:195},{id:196,label:"FM10",byte1:0,byte2:196},{id:197,label:"FM11",byte1:0,byte2:197},{id:198,label:"FM12",byte1:0,byte2:198},{id:199,label:"FM13",byte1:0,byte2:199},{id:200,label:"FM14",byte1:0,byte2:200},{id:201,label:"FM15",byte1:0,byte2:201},{id:202,label:"FM16",byte1:0,byte2:202},{id:203,label:"FM17",byte1:0,byte2:203},{id:204,label:"FM18",byte1:0,byte2:204},{id:205,label:"FM19",byte1:0,byte2:205},{id:206,label:"FM20",byte1:0,byte2:206},{id:207,label:"CCR1",byte1:0,byte2:207},{id:208,label:"CCR2",byte1:0,byte2:208},{id:209,label:"CCR3",byte1:0,byte2:209},{id:210,label:"CCR4",byte1:0,byte2:210},{id:211,label:"DME MONV",byte1:0,byte2:211},{id:212,label:"DME MONK",byte1:0,byte2:212},{id:215,label:"ME1 Out 1",byte1:0,byte2:215},{id:216,label:"ME1 Out 2",byte1:0,byte2:216},{id:217,label:"ME1 Out 3",byte1:0,byte2:217},{id:218,label:"ME1 Out 4",byte1:0,byte2:218},{id:219,label:"ME1 Out 5",byte1:0,byte2:219},{id:220,label:"ME1 Out 6",byte1:0,byte2:220},{id:221,label:"ME 1 Out 7",byte1:0,byte2:221},{id:222,label:"ME 1 Out 8",byte1:0,byte2:222},{id:223,label:"ME 1 Out 9",byte1:0,byte2:223},{id:224,label:"ME 1 Out 10",byte1:0,byte2:224},{id:225,label:"ME 1 Out 11",byte1:0,byte2:225},{id:226,label:"ME 1 Out 12",byte1:0,byte2:226},{id:227,label:"ME 1 ProcV",byte1:0,byte2:227},{id:228,label:"ME 1 ProcV-2",byte1:0,byte2:228},{id:229,label:"ME 1 ProcK",byte1:0,byte2:229},{id:230,label:"ME 1 ProcK-2",byte1:0,byte2:230},{id:231,label:"ME 2 Out 1",byte1:0,byte2:231},{id:232,label:"ME 2 Out 2",byte1:0,byte2:232},{id:233,label:"ME 2 Out 3",byte1:0,byte2:232},{id:234,label:"ME 2 Out 4",byte1:0,byte2:234},{id:235,label:"ME 2 Out 5",byte1:0,byte2:235},{id:236,label:"ME 2 Out 6",byte1:0,byte2:236},{id:237,label:"ME 2 Out 7",byte1:0,byte2:237},{id:238,label:"ME 2 Out 8",byte1:0,byte2:238},{id:239,label:"ME 2 Out 9",byte1:0,byte2:239},{id:240,label:"ME 2 Out 10",byte1:0,byte2:240},{id:241,label:"ME 2 Out 11",byte1:0,byte2:241},{id:242,label:"ME 2 Out 12",byte1:0,byte2:242},{id:243,label:"ME 2 ProcV",byte1:0,byte2:243},{id:244,label:"ME 2 ProcV-2",byte1:0,byte2:244},{id:245,label:"ME 2 ProcK",byte1:0,byte2:245},{id:246,label:"ME 2 ProcK-2",byte1:0,byte2:246},{id:247,label:"ME 3 Out 1",byte1:0,byte2:247},{id:248,label:"ME 3 Out 2",byte1:0,byte2:248},{id:249,label:"ME 3 Out 3",byte1:0,byte2:249},{id:250,label:"ME 3 Out 4",byte1:0,byte2:250},{id:251,label:"ME 3 Out 5",byte1:0,byte2:251},{id:252,label:"ME 3 Out 6",byte1:0,byte2:252},{id:253,label:"ME 3 Out 7",byte1:0,byte2:253},{id:254,label:"ME 3 Out 8",byte1:0,byte2:254},{id:255,label:"ME 3 Out 9",byte1:0,byte2:255},{id:256,label:"ME 3 Out 10",byte1:1,byte2:0},{id:257,label:"ME 3 Out 11",byte1:1,byte2:1},{id:258,label:"ME 3 Out 12",byte1:1,byte2:2},{id:259,label:"ME 3 ProcV",byte1:1,byte2:3},{id:260,label:"ME 3 ProcV-2",byte1:1,byte2:4},{id:261,label:"ME 3 ProcK",byte1:1,byte2:5},{id:262,label:"ME 3 ProcK-2",byte1:1,byte2:6},{id:263,label:"ME 4 Out 1",byte1:1,byte2:7},{id:264,label:"ME 4 Out 2",byte1:1,byte2:8},{id:265,label:"ME 4 Out 3",byte1:1,byte2:9},{id:266,label:"ME 4 Out 4",byte1:1,byte2:10},{id:267,label:"ME 4 Out 5",byte1:1,byte2:11},{id:268,label:"ME 4 Out 6",byte1:1,byte2:12},{id:269,label:"ME 4 Out 7",byte1:1,byte2:13},{id:270,label:"ME 4 Out 8",byte1:1,byte2:14},{id:271,label:"ME 4 Out 9",byte1:1,byte2:15},{id:272,label:"ME 4 Out 10",byte1:1,byte2:16},{id:273,label:"ME 4 Out 11",byte1:1,byte2:17},{id:274,label:"ME 4 Out 12",byte1:1,byte2:18},{id:275,label:"ME 4 ProcV",byte1:1,byte2:19},{id:276,label:"ME 4 ProcV-2",byte1:1,byte2:20},{id:277,label:"ME 4 ProcK",byte1:1,byte2:21},{id:278,label:"ME 4 ProcK-2",byte1:1,byte2:22},{id:279,label:"ME 5 Out 1",byte1:1,byte2:23},{id:280,label:"ME 5 Out 2",byte1:1,byte2:24},{id:281,label:"ME 5 Out 3",byte1:1,byte2:25},{id:282,label:"ME 5 Out 4",byte1:1,byte2:26},{id:283,label:"ME 5 Out 5",byte1:1,byte2:27},{id:284,label:"ME 5 Out 6",byte1:1,byte2:28},{id:285,label:"ME 5 Out 7",byte1:1,byte2:29},{id:286,label:"ME 5 Out 8",byte1:1,byte2:30},{id:287,label:"ME 5 Out 9",byte1:1,byte2:31},{id:288,label:"ME 5 Out 10",byte1:1,byte2:32},{id:289,label:"ME 5 Out 11",byte1:1,byte2:33},{id:290,label:"ME 5 Out 12",byte1:1,byte2:34},{id:291,label:"ME 5 ProcV",byte1:1,byte2:35},{id:292,label:"ME 5 ProcV-2",byte1:1,byte2:36},{id:293,label:"ME 5 ProcK",byte1:1,byte2:37},{id:294,label:"ME 5 ProcK-2",byte1:1,byte2:38},{id:295,label:"P/P Out 1",byte1:1,byte2:39},{id:296,label:"P/P Out 2",byte1:1,byte2:40},{id:297,label:"P/P Out 3",byte1:1,byte2:41},{id:298,label:"P/P Out 4",byte1:1,byte2:42},{id:299,label:"P/P Out 5",byte1:1,byte2:43},{id:300,label:"P/P Out 6",byte1:1,byte2:44},{id:301,label:"P/P Out 7",byte1:1,byte2:45},{id:302,label:"P/P Out 8",byte1:1,byte2:46},{id:303,label:"P/P Out 9",byte1:1,byte2:47},{id:304,label:"P/P Out 10",byte1:1,byte2:48},{id:305,label:"P/P Out 11",byte1:1,byte2:49},{id:306,label:"P/P Out 12",byte1:1,byte2:50},{id:307,label:"P/P ProcV",byte1:1,byte2:51},{id:308,label:"P/P ProcV-2",byte1:1,byte2:52},{id:309,label:"P/P ProcK",byte1:1,byte2:53},{id:310,label:"P/P ProcK-2",byte1:1,byte2:54}],"xvs-g1":[{id:1,label:"Primary 1",byte1:0,byte2:1},{id:2,label:"Primary 2",byte1:0,byte2:2},{id:3,label:"Primary 3",byte1:0,byte2:3},{id:4,label:"Primary 4",byte1:0,byte2:4},{id:5,label:"Primary 5",byte1:0,byte2:5},{id:6,label:"Primary 6",byte1:0,byte2:6},{id:7,label:"Primary 7",byte1:0,byte2:7},{id:8,label:"Primary 8",byte1:0,byte2:8},{id:9,label:"Primary 9",byte1:0,byte2:9},{id:10,label:"Primary 10",byte1:0,byte2:10},{id:11,label:"Primary 11",byte1:0,byte2:11},{id:12,label:"Primary 12",byte1:0,byte2:12},{id:13,label:"Primary 13",byte1:0,byte2:13},{id:14,label:"Primary 14",byte1:0,byte2:14},{id:15,label:"Primary 15",byte1:0,byte2:15},{id:16,label:"Primary 16",byte1:0,byte2:16},{id:17,label:"Primary 17",byte1:0,byte2:17},{id:18,label:"Primary 18",byte1:0,byte2:18},{id:19,label:"Primary 19",byte1:0,byte2:19},{id:20,label:"Primary 20",byte1:0,byte2:20},{id:21,label:"Primary 21",byte1:0,byte2:21},{id:22,label:"Primary 22",byte1:0,byte2:22},{id:23,label:"Primary 23",byte1:0,byte2:23},{id:24,label:"Primary 24",byte1:0,byte2:24},{id:25,label:"Primary 25",byte1:0,byte2:25},{id:26,label:"Primary 26",byte1:0,byte2:26},{id:27,label:"Primary 27",byte1:0,byte2:27},{id:28,label:"Primary 28",byte1:0,byte2:28},{id:29,label:"Primary 29",byte1:0,byte2:29},{id:30,label:"Primary 30",byte1:0,byte2:30},{id:31,label:"Primary 31",byte1:0,byte2:31},{id:32,label:"Primary 32",byte1:0,byte2:32},{id:33,label:"Primary 33",byte1:0,byte2:33},{id:34,label:"Primary 34",byte1:0,byte2:34},{id:35,label:"Primary 35",byte1:0,byte2:35},{id:36,label:"Primary 36",byte1:0,byte2:36},{id:37,label:"Primary 37",byte1:0,byte2:37},{id:38,label:"Primary 38",byte1:0,byte2:38},{id:39,label:"Primary 39",byte1:0,byte2:39},{id:40,label:"Primary 40",byte1:0,byte2:40},{id:41,label:"Primary 41",byte1:0,byte2:41},{id:42,label:"Primary 42",byte1:0,byte2:42},{id:43,label:"Primary 43",byte1:0,byte2:43},{id:44,label:"Primary 44",byte1:0,byte2:44},{id:45,label:"Primary 45",byte1:0,byte2:45},{id:46,label:"Primary 46",byte1:0,byte2:46},{id:47,label:"Primary 47",byte1:0,byte2:47},{id:48,label:"Primary 48",byte1:0,byte2:48},{id:181,label:"Black",byte1:0,byte2:181},{id:182,label:"White",byte1:0,byte2:182},{id:183,label:"Color Bkgd 1",byte1:0,byte2:183},{id:185,label:"Color Bkgd 2",byte1:0,byte2:185},{id:187,label:"FM1",byte1:0,byte2:187},{id:188,label:"FM2",byte1:0,byte2:188},{id:189,label:"FM3",byte1:0,byte2:189},{id:190,label:"FM4",byte1:0,byte2:190},{id:191,label:"FM5",byte1:0,byte2:191},{id:192,label:"FM6",byte1:0,byte2:192},{id:193,label:"FM7",byte1:0,byte2:193},{id:194,label:"FM8",byte1:0,byte2:194},{id:195,label:"FM9",byte1:0,byte2:195},{id:196,label:"FM10",byte1:0,byte2:196},{id:197,label:"FM11",byte1:0,byte2:197},{id:198,label:"FM12",byte1:0,byte2:198},{id:199,label:"FM13",byte1:0,byte2:199},{id:200,label:"FM14",byte1:0,byte2:200},{id:201,label:"FM15",byte1:0,byte2:201},{id:202,label:"FM16",byte1:0,byte2:202},{id:203,label:"CLIP1",byte1:0,byte2:203},{id:204,label:"CLIP2",byte1:0,byte2:204},{id:205,label:"CLIP3",byte1:0,byte2:205},{id:206,label:"CLIP4",byte1:0,byte2:206},{id:207,label:"(DME MON3 V)",byte1:0,byte2:207},{id:208,label:"(DME MON3 K)",byte1:0,byte2:208},{id:209,label:"(DME MON4 V)",byte1:0,byte2:209},{id:210,label:"(DME MON4 K)",byte1:0,byte2:210},{id:211,label:"DME MON1 V",byte1:0,byte2:211},{id:212,label:"DME MON1 K",byte1:0,byte2:212},{id:213,label:"(DME MON2 V)",byte1:0,byte2:213},{id:214,label:"(DME MON2 K)",byte1:0,byte2:214},{id:215,label:"ME1 Out 1",byte1:0,byte2:215},{id:216,label:"ME1 Out 2",byte1:0,byte2:216},{id:217,label:"ME1 Out 3",byte1:0,byte2:217},{id:218,label:"ME1 Out 4",byte1:0,byte2:218},{id:219,label:"ME1 Out 5",byte1:0,byte2:219},{id:220,label:"ME1 Out 6",byte1:0,byte2:220},{id:221,label:"ME 1 Out 7",byte1:0,byte2:221},{id:222,label:"ME 1 Out 8",byte1:0,byte2:222},{id:231,label:"ME 2 Out 1",byte1:0,byte2:231},{id:232,label:"ME 2 Out 2",byte1:0,byte2:232},{id:233,label:"ME 2 Out 3",byte1:0,byte2:233},{id:234,label:"ME 2 Out 4",byte1:0,byte2:234},{id:235,label:"ME 2 Out 5",byte1:0,byte2:235},{id:236,label:"ME 2 Out 6",byte1:0,byte2:236},{id:237,label:"ME 2 Out 7",byte1:0,byte2:237},{id:238,label:"ME 2 Out 8",byte1:0,byte2:238},{id:247,label:"ME 3 Out 1",byte1:0,byte2:247},{id:248,label:"ME 3 Out 2",byte1:0,byte2:248},{id:249,label:"ME 3 Out 3",byte1:0,byte2:249},{id:250,label:"ME 3 Out 4",byte1:0,byte2:250},{id:251,label:"ME 3 Out 5",byte1:0,byte2:251},{id:252,label:"ME 3 Out 6",byte1:0,byte2:252},{id:253,label:"ME 3 Out 7",byte1:0,byte2:253},{id:254,label:"ME 3 Out 8",byte1:0,byte2:254},{id:263,label:"ME 4 Out 1",byte1:1,byte2:7},{id:264,label:"ME 4 Out 2",byte1:1,byte2:8},{id:265,label:"ME 4 Out 3",byte1:1,byte2:9},{id:266,label:"ME 4 Out 4",byte1:1,byte2:10},{id:267,label:"ME 4 Out 5",byte1:1,byte2:11},{id:268,label:"ME 4 Out 6",byte1:1,byte2:12},{id:269,label:"ME 4 Out 7",byte1:1,byte2:13},{id:270,label:"ME 4 Out 8",byte1:1,byte2:14},{id:279,label:"ME 5 Out 1",byte1:1,byte2:23},{id:280,label:"ME 5 Out 2",byte1:1,byte2:24},{id:281,label:"ME 5 Out 3",byte1:1,byte2:25},{id:282,label:"ME 5 Out 4",byte1:1,byte2:26},{id:283,label:"ME 5 Out 5",byte1:1,byte2:27},{id:284,label:"ME 5 Out 6",byte1:1,byte2:28},{id:285,label:"ME 5 Out 7",byte1:1,byte2:29},{id:286,label:"ME 5 Out 8",byte1:1,byte2:30},{id:295,label:"P/P Out 1",byte1:1,byte2:39},{id:296,label:"P/P Out 2",byte1:1,byte2:40},{id:297,label:"P/P Out 3",byte1:1,byte2:41},{id:298,label:"P/P Out 4",byte1:1,byte2:42},{id:299,label:"P/P Out 5",byte1:1,byte2:43},{id:300,label:"P/P Out 6",byte1:1,byte2:44},{id:301,label:"P/P Out 7",byte1:1,byte2:45},{id:302,label:"P/P Out 8",byte1:1,byte2:46}],"mls-x1":[{id:1,label:"Primary 1",byte1:0,byte2:1},{id:2,label:"Primary 2",byte1:0,byte2:2},{id:3,label:"Primary 3",byte1:0,byte2:3},{id:4,label:"Primary 4",byte1:0,byte2:4},{id:5,label:"Primary 5",byte1:0,byte2:5},{id:6,label:"Primary 6",byte1:0,byte2:6},{id:7,label:"Primary 7",byte1:0,byte2:7},{id:8,label:"Primary 8",byte1:0,byte2:8},{id:9,label:"Primary 9",byte1:0,byte2:9},{id:10,label:"Primary 10",byte1:0,byte2:10},{id:11,label:"Primary 11",byte1:0,byte2:11},{id:12,label:"Primary 12",byte1:0,byte2:12},{id:13,label:"Primary 13",byte1:0,byte2:13},{id:14,label:"Primary 14",byte1:0,byte2:14},{id:15,label:"Primary 15",byte1:0,byte2:15},{id:16,label:"Primary 16",byte1:0,byte2:16},{id:17,label:"Primary 17",byte1:0,byte2:17},{id:18,label:"Primary 18",byte1:0,byte2:18},{id:19,label:"Primary 19",byte1:0,byte2:19},{id:20,label:"Primary 20",byte1:0,byte2:20},{id:21,label:"Primary 21",byte1:0,byte2:21},{id:22,label:"Primary 22",byte1:0,byte2:22},{id:23,label:"Primary 23",byte1:0,byte2:23},{id:24,label:"Primary 24",byte1:0,byte2:24},{id:25,label:"Primary 25",byte1:0,byte2:25},{id:26,label:"Primary 26",byte1:0,byte2:26},{id:27,label:"Primary 27",byte1:0,byte2:27},{id:28,label:"Primary 28",byte1:0,byte2:28},{id:29,label:"Primary 29",byte1:0,byte2:29},{id:30,label:"Primary 30",byte1:0,byte2:30},{id:31,label:"Primary 31",byte1:0,byte2:31},{id:32,label:"Primary 32",byte1:0,byte2:32},{id:33,label:"Primary 33",byte1:0,byte2:33},{id:34,label:"Primary 34",byte1:0,byte2:34},{id:35,label:"Primary 35",byte1:0,byte2:35},{id:36,label:"Primary 36",byte1:0,byte2:36},{id:37,label:"Primary 37",byte1:0,byte2:37},{id:38,label:"Primary 38",byte1:0,byte2:38},{id:39,label:"Primary 39",byte1:0,byte2:39},{id:40,label:"Primary 40",byte1:0,byte2:40},{id:41,label:"Primary 41",byte1:0,byte2:41},{id:42,label:"Primary 42",byte1:0,byte2:42},{id:43,label:"Primary 43",byte1:0,byte2:43},{id:44,label:"Primary 44",byte1:0,byte2:44},{id:45,label:"Primary 45",byte1:0,byte2:45},{id:46,label:"Primary 46",byte1:0,byte2:46},{id:47,label:"Primary 47",byte1:0,byte2:47},{id:48,label:"Primary 48",byte1:0,byte2:48},{id:49,label:"Primary 49",byte1:0,byte2:49},{id:50,label:"Primary 50",byte1:0,byte2:50},{id:51,label:"Primary 51",byte1:0,byte2:51},{id:52,label:"Primary 52",byte1:0,byte2:52},{id:53,label:"Primary 53",byte1:0,byte2:53},{id:54,label:"Primary 54",byte1:0,byte2:54},{id:55,label:"Primary 55",byte1:0,byte2:55},{id:56,label:"Primary 56",byte1:0,byte2:56},{id:57,label:"Primary 57",byte1:0,byte2:57},{id:58,label:"Primary 58",byte1:0,byte2:58},{id:59,label:"Primary 59",byte1:0,byte2:59},{id:60,label:"Primary 60",byte1:0,byte2:60},{id:61,label:"Primary 61",byte1:0,byte2:61},{id:62,label:"Primary 62",byte1:0,byte2:62},{id:63,label:"Primary 63",byte1:0,byte2:63},{id:64,label:"Primary 64",byte1:0,byte2:64},{id:65,label:"Primary 65",byte1:0,byte2:65},{id:66,label:"Primary 66",byte1:0,byte2:66},{id:67,label:"Primary 67",byte1:0,byte2:67},{id:68,label:"Primary 68",byte1:0,byte2:68},{id:69,label:"Primary 69",byte1:0,byte2:69},{id:70,label:"Primary 70",byte1:0,byte2:70},{id:71,label:"Primary 71",byte1:0,byte2:71},{id:72,label:"Primary 72",byte1:0,byte2:72},{id:73,label:"Primary 73",byte1:0,byte2:73},{id:74,label:"Primary 74",byte1:0,byte2:74},{id:75,label:"Primary 75",byte1:0,byte2:75},{id:76,label:"Primary 76",byte1:0,byte2:76},{id:77,label:"Primary 77",byte1:0,byte2:77},{id:78,label:"Primary 78",byte1:0,byte2:78},{id:79,label:"Primary 79",byte1:0,byte2:79},{id:80,label:"Primary 80",byte1:0,byte2:80},{id:81,label:"Primary 81",byte1:0,byte2:81},{id:82,label:"Primary 82",byte1:0,byte2:82},{id:83,label:"Primary 83",byte1:0,byte2:83},{id:84,label:"Primary 84",byte1:0,byte2:84},{id:85,label:"Primary 85",byte1:0,byte2:85},{id:86,label:"Primary 86",byte1:0,byte2:86},{id:87,label:"Primary 87",byte1:0,byte2:87},{id:88,label:"Primary 88",byte1:0,byte2:88},{id:89,label:"Primary 89",byte1:0,byte2:89},{id:90,label:"Primary 90",byte1:0,byte2:90},{id:91,label:"Primary 91",byte1:0,byte2:91},{id:92,label:"Primary 92",byte1:0,byte2:92},{id:93,label:"Primary 93",byte1:0,byte2:93},{id:94,label:"Primary 94",byte1:0,byte2:94},{id:95,label:"Primary 95",byte1:0,byte2:95},{id:96,label:"Primary 96",byte1:0,byte2:96},{id:97,label:"Primary 97",byte1:0,byte2:97},{id:98,label:"Primary 98",byte1:0,byte2:98},{id:99,label:"Primary 99",byte1:0,byte2:99},{id:100,label:"Primary 100",byte1:0,byte2:100},{id:101,label:"Primary 101",byte1:0,byte2:101},{id:102,label:"Primary 102",byte1:0,byte2:102},{id:103,label:"Primary 103",byte1:0,byte2:103},{id:104,label:"Primary 104",byte1:0,byte2:104},{id:105,label:"Primary 105",byte1:0,byte2:105},{id:106,label:"Primary 106",byte1:0,byte2:106},{id:107,label:"Primary 107",byte1:0,byte2:107},{id:108,label:"Primary 108",byte1:0,byte2:108},{id:109,label:"Primary 109",byte1:0,byte2:109},{id:110,label:"Primary 110",byte1:0,byte2:110},{id:111,label:"Primary 111",byte1:0,byte2:111},{id:112,label:"Primary 112",byte1:0,byte2:112},{id:113,label:"Primary 113",byte1:0,byte2:113},{id:114,label:"Primary 114",byte1:0,byte2:114},{id:115,label:"Primary 115",byte1:0,byte2:115},{id:116,label:"Primary 116",byte1:0,byte2:116},{id:117,label:"Primary 117",byte1:0,byte2:117},{id:118,label:"Primary 118",byte1:0,byte2:118},{id:119,label:"Primary 119",byte1:0,byte2:119},{id:120,label:"Primary 120",byte1:0,byte2:120},{id:121,label:"Primary 121",byte1:0,byte2:121},{id:122,label:"Primary 122",byte1:0,byte2:122},{id:123,label:"Primary 123",byte1:0,byte2:123},{id:124,label:"Primary 124",byte1:0,byte2:124},{id:125,label:"Primary 125",byte1:0,byte2:125},{id:126,label:"Primary 126",byte1:0,byte2:126},{id:127,label:"Primary 127",byte1:0,byte2:127},{id:128,label:"Primary 128",byte1:0,byte2:128},{id:129,label:"Primary 129",byte1:0,byte2:129},{id:130,label:"Primary 130",byte1:0,byte2:130},{id:131,label:"Primary 131",byte1:0,byte2:131},{id:132,label:"Primary 132",byte1:0,byte2:132},{id:133,label:"Primary 133",byte1:0,byte2:133},{id:134,label:"Primary 134",byte1:0,byte2:134},{id:135,label:"Primary 135",byte1:0,byte2:135},{id:136,label:"Primary 136",byte1:0,byte2:136},{id:137,label:"Primary 137",byte1:0,byte2:137},{id:138,label:"Primary 138",byte1:0,byte2:138},{id:139,label:"Primary 139",byte1:0,byte2:139},{id:140,label:"Primary 140",byte1:0,byte2:140},{id:141,label:"Primary 141",byte1:0,byte2:141},{id:142,label:"Primary 142",byte1:0,byte2:142},{id:143,label:"Primary 143",byte1:0,byte2:143},{id:144,label:"Primary 144",byte1:0,byte2:144},{id:145,label:"Primary 145",byte1:0,byte2:145},{id:146,label:"Primary 146",byte1:0,byte2:146},{id:147,label:"Primary 147",byte1:0,byte2:147},{id:148,label:"Primary 148",byte1:0,byte2:148},{id:149,label:"Primary 149",byte1:0,byte2:149},{id:150,label:"Primary 150",byte1:0,byte2:150},{id:151,label:"Primary 151",byte1:0,byte2:151},{id:152,label:"Primary 152",byte1:0,byte2:152},{id:153,label:"Primary 153",byte1:0,byte2:153},{id:154,label:"Primary 154",byte1:0,byte2:154},{id:155,label:"Primary 155",byte1:0,byte2:155},{id:156,label:"Primary 156",byte1:0,byte2:156},{id:157,label:"Primary 157",byte1:0,byte2:157},{id:158,label:"Primary 158",byte1:0,byte2:158},{id:159,label:"Primary 159",byte1:0,byte2:159},{id:160,label:"Primary 160",byte1:0,byte2:160},{id:217,label:"Black",byte1:0,byte2:217},{id:218,label:"White",byte1:0,byte2:218},{id:219,label:"Color Bkgd 1",byte1:0,byte2:219},{id:220,label:"Color Bkgd 2",byte1:0,byte2:220},{id:221,label:"FM 1",byte1:0,byte2:221},{id:222,label:"FM 2",byte1:0,byte2:222},{id:223,label:"FM 3",byte1:0,byte2:223},{id:224,label:"FM 4",byte1:0,byte2:224},{id:225,label:"FM 5",byte1:0,byte2:225},{id:226,label:"FM 6",byte1:0,byte2:226},{id:227,label:"FM 7",byte1:0,byte2:227},{id:228,label:"FM 8",byte1:0,byte2:228},{id:229,label:"FM 9",byte1:0,byte2:229},{id:230,label:"FM 10",byte1:0,byte2:230},{id:231,label:"FM 11",byte1:0,byte2:231},{id:232,label:"FM 12",byte1:0,byte2:232},{id:233,label:"FM 13",byte1:0,byte2:233},{id:234,label:"FM 14",byte1:0,byte2:234},{id:235,label:"FM 15",byte1:0,byte2:235},{id:236,label:"FM 16",byte1:0,byte2:236},{id:237,label:"FM 17",byte1:0,byte2:237},{id:238,label:"FM 18",byte1:0,byte2:238},{id:239,label:"FM 19",byte1:0,byte2:239},{id:240,label:"FM 20",byte1:0,byte2:240},{id:241,label:"FM 21",byte1:0,byte2:241},{id:242,label:"FM 22",byte1:0,byte2:242},{id:243,label:"FM 23",byte1:0,byte2:243},{id:244,label:"FM 24",byte1:0,byte2:244},{id:245,label:"FM 25",byte1:0,byte2:245},{id:246,label:"FM 26",byte1:0,byte2:246},{id:247,label:"FM 27",byte1:0,byte2:247},{id:248,label:"FM 28",byte1:0,byte2:248},{id:249,label:"FM 29",byte1:0,byte2:249},{id:250,label:"FM 30",byte1:0,byte2:250},{id:251,label:"FM 31",byte1:0,byte2:251},{id:252,label:"FM 32",byte1:0,byte2:252},{id:253,label:"CLIP1",byte1:0,byte2:253},{id:254,label:"CLIP2",byte1:0,byte2:254},{id:255,label:"CLIP3",byte1:0,byte2:255},{id:256,label:"CLIP4",byte1:1,byte2:0},{id:257,label:"CLIP5",byte1:1,byte2:1},{id:258,label:"CLIP6",byte1:1,byte2:2},{id:259,label:"CLIP7",byte1:1,byte2:3},{id:260,label:"CLIP8",byte1:1,byte2:4},{id:261,label:"DME MON V",byte1:1,byte2:5},{id:262,label:"DME MON K",byte1:1,byte2:6},{id:263,label:"ME 1 Out 1",byte1:1,byte2:7},{id:264,label:"ME 1 Out 2",byte1:1,byte2:8},{id:265,label:"ME 1 Out 3",byte1:1,byte2:9},{id:266,label:"ME 1 Out 4",byte1:1,byte2:10},{id:267,label:"ME 1 Out 5",byte1:1,byte2:11},{id:268,label:"ME 1 Out 6",byte1:1,byte2:12},{id:269,label:"ME 1 Out 7",byte1:1,byte2:13},{id:270,label:"ME 1 Out 8",byte1:1,byte2:14},{id:271,label:"ME 2 Out 1",byte1:1,byte2:15},{id:272,label:"ME 2 Out 2",byte1:1,byte2:16},{id:273,label:"ME 2 Out 3",byte1:1,byte2:17},{id:274,label:"ME 2 Out 4",byte1:1,byte2:18},{id:275,label:"ME 2 Out 5",byte1:1,byte2:19},{id:276,label:"ME 2 Out 6",byte1:1,byte2:20},{id:277,label:"ME 2 Out 7",byte1:1,byte2:21},{id:278,label:"ME 2 Out 8",byte1:1,byte2:22},{id:279,label:"ME 3 Out 1",byte1:1,byte2:23},{id:280,label:"ME 3 Out 2",byte1:1,byte2:24},{id:281,label:"ME 3 Out 3",byte1:1,byte2:25},{id:282,label:"ME 3 Out 4",byte1:1,byte2:26},{id:283,label:"ME 3 Out 5",byte1:1,byte2:27},{id:284,label:"ME 3 Out 6",byte1:1,byte2:28},{id:285,label:"ME 3 Out 7",byte1:1,byte2:29},{id:286,label:"ME 3 Out 8",byte1:1,byte2:30},{id:287,label:"ME 4 Out 1",byte1:1,byte2:31},{id:288,label:"ME 4 Out 2",byte1:1,byte2:32},{id:289,label:"ME 4 Out 3",byte1:1,byte2:33},{id:290,label:"ME 4 Out 4",byte1:1,byte2:34},{id:291,label:"ME 4 Out 5",byte1:1,byte2:35},{id:292,label:"ME 4 Out 6",byte1:1,byte2:36},{id:293,label:"ME 4 Out 7",byte1:1,byte2:37},{id:294,label:"ME 4 Out 8",byte1:1,byte2:38},{id:295,label:"ME 5 Out 1",byte1:1,byte2:39},{id:296,label:"ME 5 Out 2",byte1:1,byte2:40},{id:297,label:"ME 5 Out 3",byte1:1,byte2:41},{id:298,label:"ME 5 Out 4",byte1:1,byte2:42},{id:299,label:"ME 5 Out 5",byte1:1,byte2:43},{id:300,label:"ME 5 Out 6",byte1:1,byte2:44},{id:301,label:"ME 5 Out 7",byte1:1,byte2:45},{id:302,label:"ME 5 Out 8",byte1:1,byte2:46},{id:303,label:"P/P Out 1",byte1:1,byte2:47},{id:304,label:"P/P Out 2",byte1:1,byte2:48},{id:305,label:"P/P Out 3",byte1:1,byte2:49},{id:306,label:"P/P Out 4",byte1:1,byte2:50},{id:307,label:"P/P Out 5",byte1:1,byte2:51},{id:308,label:"P/P Out 6",byte1:1,byte2:52},{id:309,label:"P/P Out 7",byte1:1,byte2:53},{id:310,label:"P/P Out 8",byte1:1,byte2:54}]},u=[{id:"gpi1",label:"GPI 1",readByte:1},{id:"gpi2",label:"GPI 2",readByte:2},{id:"gpi3",label:"GPI 3",readByte:3},{id:"gpi4",label:"GPI 4",readByte:4},{id:"gpi5",label:"GPI 5",readByte:5},{id:"gpi6",label:"GPI 6",readByte:6},{id:"gpi7",label:"GPI 7",readByte:7},{id:"gpi8",label:"GPI 8",readByte:8}],b=[{id:"gpo1",label:"GPO 1",readByte:1},{id:"gpo2",label:"GPO 2",readByte:2},{id:"gpo3",label:"GPO 3",readByte:3},{id:"gpo4",label:"GPO 4",readByte:4},{id:"gpo5",label:"GPO 5",readByte:5},{id:"gpo6",label:"GPO 6",readByte:6},{id:"gpo7",label:"GPO 7",readByte:7},{id:"gpo8",label:"GPO 8",readByte:8}],I=[function(e,t){if(5!==t.readUint8(0))return!1;if(!r.map((e=>e.address)).includes(t.readUint8(1)))return!1;if(192!==t.readUint8(2))return!1;const n=t.readUInt8(3),i=t.readUInt8(4),s=r.find((e=>e.address===t.readUInt8(1)));if(!s)return!1;const o=d[e.config.model].find((e=>e.byte1===n&&e.byte2===i));return o?(console.log("INCOMING: FMXPT:",s,o),e.DATA.xpt[s.id]||(e.DATA.xpt[s.id]={}),e.DATA.xpt[s.id]=o.id,e.xptInterval&&clearInterval(e.xptInterval),e.xptInterval=setTimeout((()=>{e.updateVariableValues(),e.checkFeedbacks(),clearInterval(e.xptInterval)}),500),!0):(console.log("FMXPT: (NO SOURCE MATCH)",{data1:n,data2:i,foundFM:s,foundSource:o}),!1)},function(e,t){if(4!==t.readUint8(0))return!1;if(!a.map((e=>e.address)).includes(t.readUint8(1)))return!1;if(192!==t.readUint8(2))return!1;const n=t.readUInt8(3),i=t.readUInt8(4),s=a.find((e=>e.address===t.readUInt8(1)));if(!s)return!1;const o=d[e.config.model].find((e=>e.byte1===n&&e.byte2===i));return o?(console.log("INCOMING: AUXXPT:",s,o),e.DATA.xpt[s.id]||(e.DATA.xpt[s.id]={}),e.DATA.xpt[s.id]=o.id,e.xptInterval&&clearInterval(e.xptInterval),e.xptInterval=setTimeout((()=>{e.updateVariableValues(),e.checkFeedbacks(),clearInterval(e.xptInterval)}),500),!0):(console.log("AUXXPT: (NO SOURCE MATCH)",{data1:n,data2:i,foundAux:s,foundSource:o}),!1)},function(e,t){if(4!==t.readUint8(0))return!1;if(!o.map((e=>e.address)).includes(t.readUint8(1)))return!1;const n=t.readUint8(2),i=l[e.config.model]?.find((e=>n===e.writeByte));if(!i)return e.log("error","INCOMING ME XPT - NO BUS MATCH"),!1;const s=1&t.readUInt8(3),r=t.readUInt8(4),a=o.find((e=>e.address===t.readUInt8(1)));if(!a)return!1;const c=d[e.config.model].find((e=>e.byte1===s&&e.byte2===r));return c?(console.log("INCOMING: MEXPT:",a,i,c),e.DATA.xpt[a.id]||(e.DATA.xpt[a.id]={}),e.DATA.xpt[a.id][i.id]||(e.DATA.xpt[a.id][i.id]={}),e.DATA.xpt[a.id][i.id]=c.id,e.xptInterval&&clearInterval(e.xptInterval),e.xptInterval=setTimeout((()=>{e.updateVariableValues(),e.checkFeedbacks(),clearInterval(e.xptInterval)}),500),!0):(console.log("INCOMING: MEXPT: (NO SOURCE MATCH)",{foundME:a,foundBus:i,foundSource:c}),e.log("error","INCOMING ME XPT - NO SOURCE MATCH"),!1)},function(e,t){const n=t.readUint8(0);if(n<5)return!1;if(32!==t.readUint8(1))return!1;if(240!==t.readUint8(2))return!1;if(80!==t.readUint8(3))return!1;if(n>21)return console.log("ughhhg","text too long or something."),!1;const i=t.readUInt8(4),s=t.readUInt8(5),o=d[e.config.model].find((e=>e.byte1===i&&e.byte2===s));if(!o)return e.log("error","INCOMING SOURCE NAME - NO SOURCE MATCH"),console.log("INCOMING SOURCE NAME - NO SOURCE MATCH"),!1;let r="";n>=6&&255!=t.readUInt8(6)&&(r=t.subarray(6,n+1).toString());const a=e.DATA.sourceNames.find((e=>e.id===o?.id));return a?a.name=r:e.DATA.sourceNames.push({id:o?.id,name:r}),e.sourceNameUpdateTimer&&clearTimeout(e.sourceNameUpdateTimer),e.sourceNameUpdateTimer=setTimeout((()=>{e.updateActions(),e.updateFeedbacks(),e.updateVariableValues(),delete e.sourceNameUpdateTimer}),1e3),!0},function(e,t){const n=1&t.readUInt8(3),i=t.readUInt8(4);return console.log("INCOMING: GPI IN:",n,i),e.gpioUpdateTimer&&clearInterval(e.gpioUpdateTimer),e.gpioUpdateTimer=setTimeout((()=>{e.updateVariableValues(),e.checkFeedbacks(),clearInterval(e.gpioUpdateTimer)}),500),!0},function(e,t){const n=1&t.readUInt8(3),i=t.readUInt8(4);return console.log("INCOMING: GPI OUT:",n,i),e.gpioUpdateTimer&&clearInterval(e.gpioUpdateTimer),e.gpioUpdateTimer=setTimeout((()=>{e.updateVariableValues(),e.checkFeedbacks(),clearInterval(e.gpioUpdateTimer)}),500),!0}];function p(e){e.log("debug","initConnection"),e.config.host&&""!==e.config.host&&(e.log("info",`Connecting to ${e.config.host}`),e.updateStatus(i.InstanceStatus.Connecting,"Connecting"),e.tcp=new i.TCPHelper(e.config.host,e.config.port),e.PROTOCOL_STATE="IDLE",e.tcp.on("connect",(()=>{e.incomingData=Buffer.alloc(0),e.incomingCommandQueue=[],e.outgoingCommandQueue=[],e.DATA={sourceNames:[],xpt:[]},e.PROTOCOL_STATE="WAITING",e.log("debug","Connected, waiting for ACK"),e.updateStatus(i.InstanceStatus.Connecting,"Waiting for ack")})),e.tcp.on("data",(t=>{if(e.incomingData=Buffer.concat([e.incomingData,t]),132===e.incomingData.readUInt8(0)&&(console.log("got ACK"),e.incomingData=e.incomingData.subarray(1),e.updateStatus(i.InstanceStatus.Ok),e.log("debug","ACK received, connected."),"WAITING"===e.PROTOCOL_STATE&&function(e){const t=Buffer.alloc(3);for(const n of o)for(const i of l[e.config.model])t.writeUInt8(2,0),t.writeUInt8(n.address,1),t.writeUInt8(i.readByte,2),y(e,t,!1);const n=Buffer.alloc(3);for(const t of a)n.writeUInt8(2,0),n.writeUInt8(t.address,1),n.writeUInt8(64,2),y(e,n,!1);const i=Buffer.alloc(3);for(const t of r)i.writeUInt8(2,0),i.writeUInt8(t.address,1),i.writeUInt8(64,2),y(e,i,!1);const s=Buffer.alloc(6);for(const t of d[e.config.model])s.writeUInt8(5,0),s.writeUInt8(32,1),s.writeUInt8(112,2),s.writeUInt8(80,3),s.writeUInt8(t.byte1,4),s.writeUInt8(t.byte2,5),y(e,s,!1);const c=Buffer.alloc(4);c.writeUInt8(3,0),c.writeUInt8(2,1),c.writeUInt8(38,2),c.writeUInt8(1,3),y(e,c,!1)}(e),e.PROTOCOL_STATE="OK"),"OK"===e.PROTOCOL_STATE)for(;e.incomingData.length>0;){const t=e.incomingData.readUInt8(0);if(!(e.incomingData.length>=t))break;{const n=e.incomingData.subarray(0,t+1);e.incomingData=e.incomingData.subarray(t+1),e.incomingCommandQueue.push(n)}}for(;e.incomingCommandQueue.length>0;){const t=e.incomingCommandQueue.shift();t&&C(e,t)}})),e.tcp.on("error",(t=>{e.log("error",`Error: ${t}`),e.PROTOCOL_STATE="IDLE",e.updateStatus(i.InstanceStatus.UnknownError,"Connection error"),String(t).indexOf("ECONNREFUSED")>-1&&(e.tcp.destroy(),e.tcp=void 0,e.log("info","Connection refused. Will attempt to reconnect in 30 seconds."),e.reconnectInterval=setInterval((()=>{e.log("info","Attempting to reconnect..."),p(e),e.reconnectInterval=void 0}),3e4))})))}function C(e,t){!function(e,t){for(const n of I)if(n(e,t))return;console.log("UNKNOWN COMMAND>",t)}(e,t)}function h(e,t,n,i){console.log(`xptME: ${t}, ${n}, ${i}`);const s=Buffer.alloc(5),r=o.find((e=>e.id===t)),a=l[e.config.model].find((e=>e.id===n)),c=d[e.config.model].find((e=>e.id===parseInt(i)));if(r&&a&&c){const t=r.address,n=a.writeByte,i=c.byte1,o=c.byte2;s.writeUInt8(4,0),s.writeUInt8(t,1),s.writeUInt8(n,2),s.writeUInt8(i,3),s.writeUInt8(o,4),y(e,s)}}function m(e,t,n){e.log("debug",`xptAUX: ${t}, ${n}`);const i=Buffer.alloc(5),s=a.find((e=>e.id===t)),o=d[e.config.model].find((e=>e.id===parseInt(n)));if(s&&o){const t=s.address,n=o.byte1,r=o.byte2;i.writeUInt8(4,0),i.writeUInt8(t,1),i.writeUInt8(192,2),i.writeUInt8(n,3),i.writeUInt8(r,4),y(e,i)}}function y(e,t,n=!0){if(void 0!==e.tcp&&1==e.tcp.isConnected){if(1==e.config.verbose&&n){const n=t.toString("hex").match(/.{1,2}/g),i=n?n.join(" "):"";e.log("debug",`Sending: ${i}`)}e.outgoingCommandQueue.push(Buffer.from(t)),e.outputTimer||(e.outputTimer=setInterval((()=>{if(e.outgoingCommandQueue.length>0){const t=e.outgoingCommandQueue.shift();t&&e.tcp.send(t)}else clearInterval(e.outputTimer),e.outputTimer=void 0}),10))}}class Z extends i.InstanceBase{config;constructor(e){super(e)}tcp;DATA={sourceNames:[],xpt:[]};xptInterval=void 0;sourceNameUpdateTimer=void 0;gpioUpdateTimer=void 0;INTERVAL=void 0;PROTOCOL_STATE="IDLE";incomingData=Buffer.alloc(0);incomingCommandQueue=[];outgoingCommandQueue=[];outputTimer=void 0;reconnectInterval=void 0;async init(e){await this.configUpdated(e)}async destroy(){this.log("debug","destroy")}async configUpdated(e){this.config=e,this.updateStatus(i.InstanceStatus.Connecting),this.updateActions(),this.updateFeedbacks(),this.updateVariableDefinitions(),p(this)}getConfigFields(){return[{type:"static-text",id:"info",label:"Information",width:12,value:"This module is for controlling Sony XVS series switchers."},{type:"textinput",id:"host",label:"Target IP",width:8,regex:i.Regex.IP},{type:"number",id:"port",label:"Target Port",width:4,min:1,max:65535,default:10010},{type:"dropdown",id:"model",label:"Model",width:8,default:s[0].id,choices:s},{type:"static-text",id:"advancedSeperator",label:"",width:12,value:"
"},{type:"checkbox",id:"advanced",label:"Advanced settings",width:12,default:!1},{type:"checkbox",id:"verbose",label:"Verbose logging",width:4,default:!1,isVisible:e=>!!e.advanced},{type:"static-text",id:"verboseInfo",label:"",width:8,value:"Enable this to log all commands and responses to the debug log.",isVisible:e=>!!e.advanced}]}updateActions(){!function(e){const t={},n=Object.values(d[e.config.model]).map((t=>{const n=e.DATA.sourceNames.find((e=>e.id===t.id));return n&&n.name&&(t.label=`${t.label} (${n.name})`),t}));t.xptME={name:"XPT: M/E",options:[{type:"dropdown",id:"eff",label:"M/E Selection",default:o[0].id,choices:o},{type:"dropdown",id:"bus",label:"Bus Selection",default:l[e.config.model][0].id,choices:l[e.config.model]},{type:"dropdown",id:"source",label:"Source Selection",default:n[0].id,choices:n}],callback:async t=>{const n=t.options.eff,i=t.options.bus,s=t.options.source;h(e,n,i,s)}},t.copyME={name:"Copy M/E",options:[{type:"dropdown",id:"eff",label:"COPY FROM: M/E Selection",default:o[0].id,choices:o},{type:"dropdown",id:"copyEff",label:"COPY TO: M/E Selection",default:o[0].id,choices:o},{type:"dropdown",id:"bus",label:"Bus Selection",default:l[e.config.model][0].id,choices:l[e.config.model]}],callback:async t=>{const n=t.options.eff,i=t.options.copyEff,s=t.options.bus;!function(e,t,n,i){console.log(`copyME: FROM ${t}, TO ${n}, BUS ${i}`);const s=e.DATA.xpt[t];s&&h(e,n,i,s.toString())}(e,n,i,s)}},t.xptAUX={name:"XPT: AUX",options:[{type:"dropdown",id:"aux",label:"Aux Selection",default:a[0].id,choices:a},{type:"dropdown",id:"source",label:"Source Selection",default:n[0].id,choices:n}],callback:async t=>{const n=t.options.aux,i=t.options.source;m(e,n,i)}},t.copyAUX={name:"Copy AUX",options:[{type:"dropdown",id:"aux",label:"COPY FROM: Aux Selection",default:a[0].id,choices:a},{type:"dropdown",id:"copyAux",label:"COPY TO: Aux Selection",default:a[0].id,choices:a}],callback:async t=>{const n=t.options.aux,i=t.options.copyAux;!function(e,t,n){e.log("debug",`copyAUX: FROM ${t}, TO ${n}`);const i=e.DATA.xpt[t];i&&m(e,n,i.toString())}(e,n,i)}},t.transitionME={name:"Transition M/E",options:[{type:"dropdown",id:"eff",label:"M/E Selection",default:o[0].id,choices:o},{type:"dropdown",id:"cmd",label:"Command",default:c[0].id,choices:c},{type:"number",id:"transRate",label:"Transition Rate (frames)",default:30,min:0,max:999}],callback:async t=>{const n=t.options.eff,i=t.options.cmd,s=t.options.transRate;!function(e,t,n,i){e.log("debug",`transitionME: ${t}, ${n}`);const s=Buffer.alloc(7),r=o.find((e=>e.id===t)),a=c.find((e=>e.id===n));if(r&&a){const t=r.address,n=a.writeByte,o=i>>8&255,c=255&i;s.writeUInt8(6,0),s.writeUInt8(t,1),s.writeUInt8(n,2),s.writeUInt8(22,3),s.writeUInt8(0,4),s.writeUInt8(o,5),s.writeUInt8(c,6),y(e,s)}}(e,n,i,s)}},t.transitionMECancel={name:"Transition M/E Cancel",options:[{type:"dropdown",id:"eff",label:"M/E Selection",default:o[0].id,choices:o},{type:"dropdown",id:"cmd",label:"Command",default:c[0].id,choices:c}],callback:async t=>{const n=t.options.eff,i=t.options.cmd;!function(e,t,n){e.log("debug",`transitionMECancel: ${t}, ${n}`);const i=Buffer.alloc(5),s=o.find((e=>e.id===t)),r=c.find((e=>e.id===n));if(s&&r){const t=s.address,n=r.writeByte;i.writeUInt8(4,0),i.writeUInt8(t,1),i.writeUInt8(n,2),i.writeUInt8(25,3),i.writeUInt8(0,4),y(e,i)}}(e,n,i)}},t.keyOnOff={name:"Key On/Off",options:[{type:"dropdown",id:"eff",label:"M/E Selection",default:o[0].id,choices:o},{type:"dropdown",id:"key",label:"Key Number",default:g[0].id,choices:g},{type:"dropdown",id:"onoff",label:"On/Off",default:"on",choices:[{id:"on",label:"On"},{id:"off",label:"Off"}]}],callback:async t=>{const n=t.options.eff,i=t.options.key,s=t.options.onoff;!function(e,t,n,i){e.log("debug",`keyOnOff: ${t}, ${n} ${i}`);const s=Buffer.alloc(4),r=o.find((e=>e.id===t)),a=g.find((e=>e.id===n));if(r&&a){const t=r.address,n=a.address;s.writeUInt8(3,0),s.writeUInt8(t,1),"on"==i?s.writeUInt8(218,2):s.writeUInt8(154,2),s.writeUInt8(n,3),y(e,s)}}(e,n,i,s)}};const i=o.slice().reverse();t.recallSnapshot={name:"Recall Snapshot",options:[],callback:async t=>{const n=[],s=t.options.registerNumber,o=[],r=[];for(const e of i)t.options[`regionSelect_part1_${e.id}`]&&n.push(e.id);for(let e=8;e>0;e--)t.options[`regionSelect_part2_${e}`]&&o.push(e);for(const e of i)t.options[`regionSelect_part3_${e.id}`]&&r.push(e.id);!function(e,t,n,i,s){e.log("debug",`recallSnapshot: ${t}, ${n}, ${i}, ${s}`);const o=Buffer.alloc(7);let r=0,a=0,c=0;const l=t.includes("me5")?1:0,g=t.includes("me4")?1:0,d=t.includes("me3")?1:0,u=t.includes("me2")?1:0,b=t.includes("me1")?1:0,I=t.includes("pp")?1:0;r=parseInt(`00${l}${g}${d}${u}${b}${I}`,2);const p=i.includes(8)?1:0,C=i.includes(7)?1:0,h=i.includes(6)?1:0,m=i.includes(5)?1:0,Z=i.includes(4)?1:0,G=i.includes(3)?1:0,B=i.includes(2)?1:0,A=i.includes(1)?1:0;a=parseInt(`${p}${C}${h}${m}${Z}${G}${B}${A}`,2);const W=s.includes("me5")?1:0,f=s.includes("me4")?1:0,V=s.includes("me3")?1:0,v=s.includes("me2")?1:0,R=s.includes("me1")?1:0,Y=s.includes("pp")?1:0;c=parseInt(`00${W}${f}${V}${v}${R}${Y}`,2),o.writeUInt8(6,0),o.writeUInt8(33,1),o.writeUInt8(144,2),o.writeUInt8(r,3),o.writeUInt8(n,4),o.writeUInt8(a,5),o.writeUInt8(c,6),y(e,o)}(e,n,s,o,r)}};for(const e of i){const n={type:"checkbox",id:`regionSelect_part1_${e.id}`,label:`Region Select Part 1 - ${e.label}`,default:!1};t.recallSnapshot.options.push(n)}t.recallSnapshot.options.push({type:"number",id:"registerNumber",label:"Register Number",default:1,min:1,max:99});for(let e=8;e>0;e--){const n={type:"checkbox",id:`regionSelect_part2_${e}`,label:`Region Select Part 2 - User ${e}`,default:!1};t.recallSnapshot.options.push(n)}for(const e of i){const n={type:"checkbox",id:`regionSelect_part3_${e.id}`,label:`Region Select Part 3 - ${e.label} SUB`,default:!1};t.recallSnapshot.options.push(n)}t.macroRecall={name:"Macro Recall",options:[{type:"number",id:"macroNumber",label:"Macro Register Number",default:1,min:1,max:999}],callback:async t=>{const n=t.options.macroNumber;!function(e,t){e.log("debug",`macroRecall: ${t}`);const n=Buffer.alloc(7);let i=0,s=0;const o=parseInt(t);i=o>>8&255,s=255&o,n.writeUInt8(6,0),n.writeUInt8(34,1),n.writeUInt8(145,2),n.writeUInt8(0,3),n.writeUInt8(23,4),n.writeUInt8(i,5),n.writeUInt8(s,6),y(e,n)}(e,n)}},t.macroTake={name:"Macro Take",options:[],callback:async()=>{!function(e){e.log("debug","macroTake");const t=Buffer.alloc(5);t.writeUInt8(4,0),t.writeUInt8(34,1),t.writeUInt8(144,2),t.writeUInt8(0,3),t.writeUInt8(28,4),y(e,t)}(e)}},t.gpiIn={name:"Activate GPI In",options:[{type:"number",id:"gpiNumber",label:"GPI Number",default:1,min:1,max:999},{type:"dropdown",id:"gpiState",label:"GPI State",default:0,choices:[{id:0,label:"High"},{id:1,label:"Low"}]}],callback:async t=>{const n=t.options.gpiNumber,i=t.options.gpiState;!function(e,t,n){e.log("debug",`activate gpiIn: ${t}, ${n}`);const i=Buffer.alloc(5);i.writeUInt8(4,0),i.writeUInt8(38,1),i.writeUInt8(128,2),i.writeUInt8(t,3),i.writeUInt8(n,4),y(e,i)}(e,n,i)}},t.gpiOut={name:"Activate GPI Out",options:[{type:"number",id:"gpiNumber",label:"GPI Number",default:1,min:1,max:999},{type:"dropdown",id:"gpiState",label:"GPI State",default:1,choices:[{id:1,label:"High"},{id:0,label:"Low"}]}],callback:async t=>{const n=t.options.gpiNumber,i=t.options.gpiState;!function(e,t,n){e.log("debug",`activate gpiOut: ${t}, ${n}`);const i=Buffer.alloc(5);i.writeUInt8(4,0),i.writeUInt8(38,1),i.writeUInt8(129,2),i.writeUInt8(t,3),i.writeUInt8(n,4),y(e,i)}(e,n,i)}},t.customCommand={name:"Send Custom Command",options:[{type:"static-text",id:"info",label:"Send a custom command string to the device",value:"The command must conform to the Sony XVS protocol or it will be rejected. Use with caution."},{type:"static-text",id:"example",label:"Example",value:"0431C00001 would send Source 1 to Aux 2."},{type:"textinput",label:"Command String",id:"commandString",default:""}],callback:async t=>{const n=await e.parseVariablesInString(t.options.commandString?.toString()??"");!function(e,t){e.log("debug",`customCommand: ${t}`),y(e,Buffer.from(t,"hex"))}(e,n)}},e.setActionDefinitions(t)}(this)}updateFeedbacks(){!function(e){const t={};t.xptMEState={name:"Selected Source is on Selected Bus of M/E",type:"boolean",defaultStyle:{bgcolor:(0,i.combineRgb)(255,0,0),color:(0,i.combineRgb)(0,0,0)},options:[{type:"dropdown",id:"eff",label:"M/E Selection",default:o[0].id,choices:o},{type:"dropdown",id:"bus",label:"Bus Selection",default:l[e.config.model][0].id,choices:l[e.config.model]},{type:"dropdown",id:"source",label:"Source Selection",default:d[e.config.model][0].id,choices:d[e.config.model]}],callback:t=>{const n=t.options.eff,i=t.options.bus,s=t.options.source;return!(!e.DATA.xpt[n]||!e.DATA.xpt[n][i]||e.DATA.xpt[n][i]!=s)}},t.xptAUXState={name:"Selected Source is on Selected Aux",type:"boolean",defaultStyle:{bgcolor:(0,i.combineRgb)(255,0,0),color:(0,i.combineRgb)(0,0,0)},options:[{type:"dropdown",id:"aux",label:"Aux Selection",default:a[0].id,choices:a},{type:"dropdown",id:"source",label:"Source Selection",default:d[e.config.model][0].id,choices:d[e.config.model]}],callback:t=>{const n=t.options.aux,i=t.options.source;return e.DATA.xpt[n]==i}},e.setFeedbackDefinitions(t)}(this)}updateVariableDefinitions(){!function(e){const t=[];for(const n of o)for(const i of l[e.config.model])t.push({name:`${n.label} ${i.label}`,variableId:`${n.id}_${i.id}`});for(const n of d[e.config.model])t.push({name:`${n.label} Name`,variableId:`source_${n.id}`});for(const e of a)t.push({name:`${e.label}`,variableId:`${e.id}`});for(const e of r)t.push({name:`${e.label}`,variableId:`${e.id}`});for(const e of u)t.push({name:`${e.label} State`,variableId:`${e.id}`});for(const e of b)t.push({name:`${e.label} State`,variableId:`${e.id}`});e.setVariableDefinitions(t)}(this)}updateVariableValues(){!function(e){const t={};for(const n of o)for(const i of l[e.config.model]){const s=e.DATA.xpt[n.id]?.[i.id],o=d[e.config.model].find((e=>e.id===s))?.label;if(s&&o){t[`${n.id}_${i.id}`]=o;const r=e.DATA.sourceNames.find((e=>e.id===s));r&&(t[`${n.id}_${i.id}`]=r.name)}else e.log("debug",`UpdateVariableValues: No source found for ${n.id}_${i.id}`)}for(const n of d[e.config.model]){const i=e.DATA.sourceNames.find((e=>e.id===n.id));i?t[`source_${n.id}`]=i.name:e.log("debug",`UpdateVariableValues: No source name found for ${n.id}`)}for(const n of a){const i=e.DATA.xpt[n.id],s=d[e.config.model].find((e=>e.id===i))?.label;if(i&&s){t[`${n.id}`]=s;const o=e.DATA.sourceNames.find((e=>e.id===i));o&&(t[`${n.id}`]=o.name)}else e.log("debug",`UpdateVariableValues: No source found for ${n.id}`)}for(const n of r){const i=e.DATA.xpt[n.id],s=d[e.config.model].find((e=>e.id===i))?.label;if(i&&s){t[`${n.id}`]=s;const o=e.DATA.sourceNames.find((e=>e.id===i));o&&(t[`${n.id}`]=o.name)}else e.log("debug",`UpdateVariableValues: No source found for ${n.id}`)}for(const n of u){const i=e.DATA.gpi?.[n.id]??null;t[`${n.id}`]=i?"On":"Off"}for(const n of b){const i=e.DATA.gpo?.[n.id]??null;t[`${n.id}`]=i?"On":"Off"}e.setVariableValues(t)}(this)}}(0,i.runEntrypoint)(Z,[])},1635:(e,t,n)=>{"use strict";n.r(t),n.d(t,{__addDisposableResource:()=>w,__assign:()=>o,__asyncDelegator:()=>f,__asyncGenerator:()=>W,__asyncValues:()=>V,__await:()=>A,__awaiter:()=>I,__classPrivateFieldGet:()=>H,__classPrivateFieldIn:()=>N,__classPrivateFieldSet:()=>S,__createBinding:()=>C,__decorate:()=>a,__disposeResources:()=>F,__esDecorate:()=>l,__exportStar:()=>h,__extends:()=>s,__generator:()=>p,__importDefault:()=>X,__importStar:()=>Y,__makeTemplateObject:()=>v,__metadata:()=>b,__param:()=>c,__propKey:()=>d,__read:()=>y,__rest:()=>r,__runInitializers:()=>g,__setFunctionName:()=>u,__spread:()=>Z,__spreadArray:()=>B,__spreadArrays:()=>G,__values:()=>m,default:()=>k});var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},i(e,t)};function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var o=function(){return o=Object.assign||function(e){for(var t,n=1,i=arguments.length;n=0;a--)(s=e[a])&&(r=(o<3?s(r):o>3?s(t,n,r):s(t,n))||r);return o>3&&r&&Object.defineProperty(t,n,r),r}function c(e,t){return function(n,i){t(n,i,e)}}function l(e,t,n,i,s,o){function r(e){if(void 0!==e&&"function"!=typeof e)throw new TypeError("Function expected");return e}for(var a,c=i.kind,l="getter"===c?"get":"setter"===c?"set":"value",g=!t&&e?i.static?e:e.prototype:null,d=t||(g?Object.getOwnPropertyDescriptor(g,i.name):{}),u=!1,b=n.length-1;b>=0;b--){var I={};for(var p in i)I[p]="access"===p?{}:i[p];for(var p in i.access)I.access[p]=i.access[p];I.addInitializer=function(e){if(u)throw new TypeError("Cannot add initializers after decoration has completed");o.push(r(e||null))};var C=(0,n[b])("accessor"===c?{get:d.get,set:d.set}:d[l],I);if("accessor"===c){if(void 0===C)continue;if(null===C||"object"!=typeof C)throw new TypeError("Object expected");(a=r(C.get))&&(d.get=a),(a=r(C.set))&&(d.set=a),(a=r(C.init))&&s.unshift(a)}else(a=r(C))&&("field"===c?s.unshift(a):d[l]=a)}g&&Object.defineProperty(g,i.name,d),u=!0}function g(e,t,n){for(var i=arguments.length>2,s=0;s0&&s[s.length-1])||6!==a[0]&&2!==a[0])){r=0;continue}if(3===a[0]&&(!s||a[1]>s[0]&&a[1]=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function y(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var i,s,o=n.call(e),r=[];try{for(;(void 0===t||t-- >0)&&!(i=o.next()).done;)r.push(i.value)}catch(e){s={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(s)throw s.error}}return r}function Z(){for(var e=[],t=0;t1||a(e,t)}))},t&&(i[e]=t(i[e])))}function a(e,t){try{(n=s[e](t)).value instanceof A?Promise.resolve(n.value.v).then(c,l):g(o[0][2],n)}catch(e){g(o[0][3],e)}var n}function c(e){a("next",e)}function l(e){a("throw",e)}function g(e,t){e(t),o.shift(),o.length&&a(o[0][0],o[0][1])}}function f(e){var t,n;return t={},i("next"),i("throw",(function(e){throw e})),i("return"),t[Symbol.iterator]=function(){return this},t;function i(i,s){t[i]=e[i]?function(t){return(n=!n)?{value:A(e[i](t)),done:!1}:s?s(t):t}:s}}function V(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=m(e),t={},i("next"),i("throw"),i("return"),t[Symbol.asyncIterator]=function(){return this},t);function i(n){t[n]=e[n]&&function(t){return new Promise((function(i,s){!function(e,t,n,i){Promise.resolve(i).then((function(t){e({value:t,done:n})}),t)}(i,s,(t=e[n](t)).done,t.value)}))}}}function v(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}var R=Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t};function Y(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&C(t,e,n);return R(t,e),t}function X(e){return e&&e.__esModule?e:{default:e}}function H(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function S(e,t,n,i,s){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?s.call(e,n):s?s.value=n:t.set(e,n),n}function N(e,t){if(null===t||"object"!=typeof t&&"function"!=typeof t)throw new TypeError("Cannot use 'in' operator on non-object");return"function"==typeof e?t===e:e.has(t)}function w(e,t,n){if(null!=t){if("object"!=typeof t&&"function"!=typeof t)throw new TypeError("Object expected.");var i,s;if(n){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");i=t[Symbol.asyncDispose]}if(void 0===i){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");i=t[Symbol.dispose],n&&(s=i)}if("function"!=typeof i)throw new TypeError("Object not disposable.");s&&(i=function(){try{s.call(this)}catch(e){return Promise.reject(e)}}),e.stack.push({value:t,dispose:i,async:n})}else n&&e.stack.push({async:!0});return t}var K="function"==typeof SuppressedError?SuppressedError:function(e,t,n){var i=new Error(n);return i.name="SuppressedError",i.error=e,i.suppressed=t,i};function F(e){function t(t){e.error=e.hasError?new K(t,e.error,"An error was suppressed during disposal."):t,e.hasError=!0}return function n(){for(;e.stack.length;){var i=e.stack.pop();try{var s=i.dispose&&i.dispose.call(i.value);if(i.async)return Promise.resolve(s).then(n,(function(e){return t(e),n()}))}catch(e){t(e)}}if(e.hasError)throw e.error}()}const k={__extends:s,__assign:o,__rest:r,__decorate:a,__param:c,__metadata:b,__awaiter:I,__generator:p,__createBinding:C,__exportStar:h,__values:m,__read:y,__spread:Z,__spreadArrays:G,__spreadArray:B,__await:A,__asyncGenerator:W,__asyncDelegator:f,__asyncValues:V,__makeTemplateObject:v,__importStar:Y,__importDefault:X,__classPrivateFieldGet:H,__classPrivateFieldSet:S,__classPrivateFieldIn:N,__addDisposableResource:w,__disposeResources:F}}},t={};function n(i){var s=t[i];if(void 0!==s)return s.exports;var o=t[i]={id:i,loaded:!1,exports:{}};return e[i](o,o.exports,n),o.loaded=!0,o.exports}n.c=t,n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.hmd=e=>((e=Object.create(e)).children||(e.children=[]),Object.defineProperty(e,"exports",{enumerable:!0,set:()=>{throw new Error("ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: "+e.id)}}),e),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n(n.s=8515)})(); \ No newline at end of file +(()=>{var e={7169:(e,t,n)=>{"use strict";const i=n(2017);i.code='require("ajv/dist/runtime/equal").default',t.A=i},2581:(e,t,n)=>{"use strict";n.d(t,{l:()=>r});var i=n(6588),s=n(1763),o=n(8560);function r(){(0,s.U)(),(0,o.wD)()&&function(){const t=(0,i.EU)();if(!t.__SENTRY__)return;const n={mongodb:()=>new((0,o.fj)(e,"./node/integrations/mongo").Mongo),mongoose:()=>new((0,o.fj)(e,"./node/integrations/mongo").Mongo),mysql:()=>new((0,o.fj)(e,"./node/integrations/mysql").Mysql),pg:()=>new((0,o.fj)(e,"./node/integrations/postgres").Postgres)},s=Object.keys(n).filter((e=>!!(0,o.Vw)(e))).map((e=>{try{return n[e]()}catch(e){return}})).filter((e=>e));s.length>0&&(t.__SENTRY__.integrations=[...t.__SENTRY__.integrations||[],...s])}()}e=n.hmd(e)},7765:(e,t,n)=>{"use strict";n.d(t,{U:()=>i});const i="production"},7022:(e,t,n)=>{"use strict";n.d(t,{T:()=>i});const i="undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__},9071:(e,t,n)=>{"use strict";n.d(t,{KU:()=>o,o5:()=>r,v4:()=>s});var i=n(6588);function s(...e){const t=(0,i.BF)();if(2===e.length){const[n,i]=e;return n?t.withScope((()=>(t.getStackTop().scope=n,i(n)))):t.withScope(i)}return t.withScope(e[0])}function o(){return(0,i.BF)().getClient()}function r(){return(0,i.BF)().getScope()}},6588:(e,t,n)=>{"use strict";n.d(t,{BF:()=>f,rm:()=>V,EU:()=>A,fx:()=>v});var i,s=n(138),o=n(4902),r=n(7567),a=n(6202),c=n(2231),l=n(7765),g=n(7022);!function(e){e[e.PENDING=0]="PENDING",e[e.RESOLVED=1]="RESOLVED",e[e.REJECTED=2]="REJECTED"}(i||(i={}));class d{constructor(e){d.prototype.__init.call(this),d.prototype.__init2.call(this),d.prototype.__init3.call(this),d.prototype.__init4.call(this),this._state=i.PENDING,this._handlers=[];try{e(this._resolve,this._reject)}catch(e){this._reject(e)}}then(e,t){return new d(((n,i)=>{this._handlers.push([!1,t=>{if(e)try{n(e(t))}catch(e){i(e)}else n(t)},e=>{if(t)try{n(t(e))}catch(e){i(e)}else i(e)}]),this._executeHandlers()}))}catch(e){return this.then((e=>e),e)}finally(e){return new d(((t,n)=>{let i,s;return this.then((t=>{s=!1,i=t,e&&e()}),(t=>{s=!0,i=t,e&&e()})).then((()=>{s?n(i):t(i)}))}))}__init(){this._resolve=e=>{this._setResult(i.RESOLVED,e)}}__init2(){this._reject=e=>{this._setResult(i.REJECTED,e)}}__init3(){this._setResult=(e,t)=>{this._state===i.PENDING&&((0,s.Qg)(t)?t.then(this._resolve,this._reject):(this._state=e,this._value=t,this._executeHandlers()))}}__init4(){this._executeHandlers=()=>{if(this._state===i.PENDING)return;const e=this._handlers.slice();this._handlers=[],e.forEach((e=>{e[0]||(this._state===i.RESOLVED&&e[1](this._value),this._state===i.REJECTED&&e[2](this._value),e[0]=!0)}))}}}function u(e,t,n,i=0){return new d(((o,r)=>{const c=e[i];if(null===t||"function"!=typeof c)o(t);else{const l=c({...t},n);g.T&&c.id&&null===l&&a.vF.log(`Event processor "${c.id}" dropped event`),(0,s.Qg)(l)?l.then((t=>u(e,t,n,i+1).then(o))).then(null,r):u(e,l,n,i+1).then(o).then(null,r)}}))}var b=n(1041);function I(e,t={}){if(t.user&&(!e.ipAddress&&t.user.ip_address&&(e.ipAddress=t.user.ip_address),e.did||t.did||(e.did=t.user.id||t.user.email||t.user.username)),e.timestamp=t.timestamp||(0,r.zf)(),t.abnormal_mechanism&&(e.abnormal_mechanism=t.abnormal_mechanism),t.ignoreDuration&&(e.ignoreDuration=t.ignoreDuration),t.sid&&(e.sid=32===t.sid.length?t.sid:(0,o.eJ)()),void 0!==t.init&&(e.init=t.init),!e.did&&t.did&&(e.did=`${t.did}`),"number"==typeof t.started&&(e.started=t.started),e.ignoreDuration)e.duration=void 0;else if("number"==typeof t.duration)e.duration=t.duration;else{const t=e.timestamp-e.started;e.duration=t>=0?t:0}t.release&&(e.release=t.release),t.environment&&(e.environment=t.environment),!e.ipAddress&&t.ipAddress&&(e.ipAddress=t.ipAddress),!e.userAgent&&t.userAgent&&(e.userAgent=t.userAgent),"number"==typeof t.errors&&(e.errors=t.errors),t.status&&(e.status=t.status)}var p=n(9738),C=n(9266),h=n(5895);class m{constructor(){this._notifyingListeners=!1,this._scopeListeners=[],this._eventProcessors=[],this._breadcrumbs=[],this._attachments=[],this._user={},this._tags={},this._extra={},this._contexts={},this._sdkProcessingMetadata={},this._propagationContext=y()}static clone(e){return e?e.clone():new m}clone(){const e=new m;return e._breadcrumbs=[...this._breadcrumbs],e._tags={...this._tags},e._extra={...this._extra},e._contexts={...this._contexts},e._user=this._user,e._level=this._level,e._span=this._span,e._session=this._session,e._transactionName=this._transactionName,e._fingerprint=this._fingerprint,e._eventProcessors=[...this._eventProcessors],e._requestSession=this._requestSession,e._attachments=[...this._attachments],e._sdkProcessingMetadata={...this._sdkProcessingMetadata},e._propagationContext={...this._propagationContext},e._client=this._client,e}setClient(e){this._client=e}getClient(){return this._client}addScopeListener(e){this._scopeListeners.push(e)}addEventProcessor(e){return this._eventProcessors.push(e),this}setUser(e){return this._user=e||{email:void 0,id:void 0,ip_address:void 0,segment:void 0,username:void 0},this._session&&I(this._session,{user:e}),this._notifyScopeListeners(),this}getUser(){return this._user}getRequestSession(){return this._requestSession}setRequestSession(e){return this._requestSession=e,this}setTags(e){return this._tags={...this._tags,...e},this._notifyScopeListeners(),this}setTag(e,t){return this._tags={...this._tags,[e]:t},this._notifyScopeListeners(),this}setExtras(e){return this._extra={...this._extra,...e},this._notifyScopeListeners(),this}setExtra(e,t){return this._extra={...this._extra,[e]:t},this._notifyScopeListeners(),this}setFingerprint(e){return this._fingerprint=e,this._notifyScopeListeners(),this}setLevel(e){return this._level=e,this._notifyScopeListeners(),this}setTransactionName(e){return this._transactionName=e,this._notifyScopeListeners(),this}setContext(e,t){return null===t?delete this._contexts[e]:this._contexts[e]=t,this._notifyScopeListeners(),this}setSpan(e){return this._span=e,this._notifyScopeListeners(),this}getSpan(){return this._span}getTransaction(){const e=this._span;return e&&e.transaction}setSession(e){return e?this._session=e:delete this._session,this._notifyScopeListeners(),this}getSession(){return this._session}update(e){if(!e)return this;const t="function"==typeof e?e(this):e;if(t instanceof m){const e=t.getScopeData();this._tags={...this._tags,...e.tags},this._extra={...this._extra,...e.extra},this._contexts={...this._contexts,...e.contexts},e.user&&Object.keys(e.user).length&&(this._user=e.user),e.level&&(this._level=e.level),e.fingerprint.length&&(this._fingerprint=e.fingerprint),t.getRequestSession()&&(this._requestSession=t.getRequestSession()),e.propagationContext&&(this._propagationContext=e.propagationContext)}else if((0,s.Qd)(t)){const t=e;this._tags={...this._tags,...t.tags},this._extra={...this._extra,...t.extra},this._contexts={...this._contexts,...t.contexts},t.user&&(this._user=t.user),t.level&&(this._level=t.level),t.fingerprint&&(this._fingerprint=t.fingerprint),t.requestSession&&(this._requestSession=t.requestSession),t.propagationContext&&(this._propagationContext=t.propagationContext)}return this}clear(){return this._breadcrumbs=[],this._tags={},this._extra={},this._user={},this._contexts={},this._level=void 0,this._transactionName=void 0,this._fingerprint=void 0,this._requestSession=void 0,this._span=void 0,this._session=void 0,this._notifyScopeListeners(),this._attachments=[],this._propagationContext=y(),this}addBreadcrumb(e,t){const n="number"==typeof t?t:100;if(n<=0)return this;const i={timestamp:(0,r.lu)(),...e},s=this._breadcrumbs;return s.push(i),this._breadcrumbs=s.length>n?s.slice(-n):s,this._notifyScopeListeners(),this}getLastBreadcrumb(){return this._breadcrumbs[this._breadcrumbs.length-1]}clearBreadcrumbs(){return this._breadcrumbs=[],this._notifyScopeListeners(),this}addAttachment(e){return this._attachments.push(e),this}getAttachments(){return this.getScopeData().attachments}clearAttachments(){return this._attachments=[],this}getScopeData(){const{_breadcrumbs:e,_attachments:t,_contexts:n,_tags:i,_extra:s,_user:o,_level:r,_fingerprint:a,_eventProcessors:c,_propagationContext:l,_sdkProcessingMetadata:g,_transactionName:d,_span:u}=this;return{breadcrumbs:e,attachments:t,contexts:n,tags:i,extra:s,user:o,level:r,fingerprint:a||[],eventProcessors:c,propagationContext:l,sdkProcessingMetadata:g,transactionName:d,span:u}}applyToEvent(e,t={},n=[]){return function(e,t){const{fingerprint:n,span:i,breadcrumbs:s,sdkProcessingMetadata:r}=t;!function(e,t){const{extra:n,tags:i,user:s,contexts:o,level:r,transactionName:a}=t,c=(0,b.Ce)(n);c&&Object.keys(c).length&&(e.extra={...c,...e.extra});const l=(0,b.Ce)(i);l&&Object.keys(l).length&&(e.tags={...l,...e.tags});const g=(0,b.Ce)(s);g&&Object.keys(g).length&&(e.user={...g,...e.user});const d=(0,b.Ce)(o);d&&Object.keys(d).length&&(e.contexts={...d,...e.contexts}),r&&(e.level=r),a&&(e.transaction=a)}(e,t),i&&function(e,t){e.contexts={trace:(0,h.kX)(t),...e.contexts};const n=(0,C.z)(t);if(n){e.sdkProcessingMetadata={dynamicSamplingContext:(0,p.k)(t),...e.sdkProcessingMetadata};const i=(0,h.et)(n).description;i&&(e.tags={transaction:i,...e.tags})}}(e,i),function(e,t){e.fingerprint=e.fingerprint?(0,o.k9)(e.fingerprint):[],t&&(e.fingerprint=e.fingerprint.concat(t)),e.fingerprint&&!e.fingerprint.length&&delete e.fingerprint}(e,n),function(e,t){const n=[...e.breadcrumbs||[],...t];e.breadcrumbs=n.length?n:void 0}(e,s),function(e,t){e.sdkProcessingMetadata={...e.sdkProcessingMetadata,...t}}(e,r)}(e,this.getScopeData()),u([...n,...(0,c.BY)("globalEventProcessors",(()=>[])),...this._eventProcessors],e,t)}setSDKProcessingMetadata(e){return this._sdkProcessingMetadata={...this._sdkProcessingMetadata,...e},this}setPropagationContext(e){return this._propagationContext=e,this}getPropagationContext(){return this._propagationContext}captureException(e,t){const n=t&&t.event_id?t.event_id:(0,o.eJ)();if(!this._client)return a.vF.warn("No client configured on scope - will not capture exception!"),n;const i=new Error("Sentry syntheticException");return this._client.captureException(e,{originalException:e,syntheticException:i,...t,event_id:n},this),n}captureMessage(e,t,n){const i=n&&n.event_id?n.event_id:(0,o.eJ)();if(!this._client)return a.vF.warn("No client configured on scope - will not capture message!"),i;const s=new Error(e);return this._client.captureMessage(e,t,{originalException:e,syntheticException:s,...n,event_id:i},this),i}captureEvent(e,t){const n=t&&t.event_id?t.event_id:(0,o.eJ)();return this._client?(this._client.captureEvent(e,{...t,event_id:n},this),n):(a.vF.warn("No client configured on scope - will not capture event!"),n)}_notifyScopeListeners(){this._notifyingListeners||(this._notifyingListeners=!0,this._scopeListeners.forEach((e=>{e(this)})),this._notifyingListeners=!1)}}function y(){return{traceId:(0,o.eJ)(),spanId:(0,o.eJ)().substring(16)}}const Z=parseFloat("7.114.0"),G=100;class B{constructor(e,t,n,i=Z){let s,o;this._version=i,t?s=t:(s=new m,s.setClient(e)),n?o=n:(o=new m,o.setClient(e)),this._stack=[{scope:s}],e&&this.bindClient(e),this._isolationScope=o}isOlderThan(e){return this._version(this.popScope(),e)),(e=>{throw this.popScope(),e})):(this.popScope(),n)}getClient(){return this.getStackTop().client}getScope(){return this.getStackTop().scope}getIsolationScope(){return this._isolationScope}getStack(){return this._stack}getStackTop(){return this._stack[this._stack.length-1]}captureException(e,t){const n=this._lastEventId=t&&t.event_id?t.event_id:(0,o.eJ)(),i=new Error("Sentry syntheticException");return this.getScope().captureException(e,{originalException:e,syntheticException:i,...t,event_id:n}),n}captureMessage(e,t,n){const i=this._lastEventId=n&&n.event_id?n.event_id:(0,o.eJ)(),s=new Error(e);return this.getScope().captureMessage(e,t,{originalException:e,syntheticException:s,...n,event_id:i}),i}captureEvent(e,t){const n=t&&t.event_id?t.event_id:(0,o.eJ)();return e.type||(this._lastEventId=n),this.getScope().captureEvent(e,{...t,event_id:n}),n}lastEventId(){return this._lastEventId}addBreadcrumb(e,t){const{scope:n,client:i}=this.getStackTop();if(!i)return;const{beforeBreadcrumb:s=null,maxBreadcrumbs:o=G}=i.getOptions&&i.getOptions()||{};if(o<=0)return;const c={timestamp:(0,r.lu)(),...e},l=s?(0,a.pq)((()=>s(c,t))):c;null!==l&&(i.emit&&i.emit("beforeAddBreadcrumb",l,t),n.addBreadcrumb(l,o))}setUser(e){this.getScope().setUser(e),this.getIsolationScope().setUser(e)}setTags(e){this.getScope().setTags(e),this.getIsolationScope().setTags(e)}setExtras(e){this.getScope().setExtras(e),this.getIsolationScope().setExtras(e)}setTag(e,t){this.getScope().setTag(e,t),this.getIsolationScope().setTag(e,t)}setExtra(e,t){this.getScope().setExtra(e,t),this.getIsolationScope().setExtra(e,t)}setContext(e,t){this.getScope().setContext(e,t),this.getIsolationScope().setContext(e,t)}configureScope(e){const{scope:t,client:n}=this.getStackTop();n&&e(t)}run(e){const t=W(this);try{e(this)}finally{W(t)}}getIntegration(e){const t=this.getClient();if(!t)return null;try{return t.getIntegration(e)}catch(t){return g.T&&a.vF.warn(`Cannot retrieve integration ${e.id} from the current Hub`),null}}startTransaction(e,t){const n=this._callExtensionMethod("startTransaction",e,t);return g.T&&!n&&(this.getClient()?a.vF.warn("Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init':\nSentry.addTracingExtensions();\nSentry.init({...});\n"):a.vF.warn("Tracing extension 'startTransaction' is missing. You should 'init' the SDK before calling 'startTransaction'")),n}traceHeaders(){return this._callExtensionMethod("traceHeaders")}captureSession(e=!1){if(e)return this.endSession();this._sendSessionUpdate()}endSession(){const e=this.getStackTop().scope,t=e.getSession();t&&function(e){let t={};"ok"===e.status&&(t={status:"exited"}),I(e,t)}(t),this._sendSessionUpdate(),e.setSession()}startSession(e){const{scope:t,client:n}=this.getStackTop(),{release:i,environment:s=l.U}=n&&n.getOptions()||{},{userAgent:a}=c.OW.navigator||{},g=function(e){const t=(0,r.zf)(),n={sid:(0,o.eJ)(),init:!0,timestamp:t,started:t,duration:0,status:"ok",errors:0,ignoreDuration:!1,toJSON:()=>function(e){return(0,b.Ce)({sid:`${e.sid}`,init:e.init,started:new Date(1e3*e.started).toISOString(),timestamp:new Date(1e3*e.timestamp).toISOString(),status:e.status,errors:e.errors,did:"number"==typeof e.did||"string"==typeof e.did?`${e.did}`:void 0,duration:e.duration,abnormal_mechanism:e.abnormal_mechanism,attrs:{release:e.release,environment:e.environment,ip_address:e.ipAddress,user_agent:e.userAgent}})}(n)};return e&&I(n,e),n}({release:i,environment:s,user:t.getUser(),...a&&{userAgent:a},...e}),d=t.getSession&&t.getSession();return d&&"ok"===d.status&&I(d,{status:"exited"}),this.endSession(),t.setSession(g),g}shouldSendDefaultPii(){const e=this.getClient(),t=e&&e.getOptions();return Boolean(t&&t.sendDefaultPii)}_sendSessionUpdate(){const{scope:e,client:t}=this.getStackTop(),n=e.getSession();n&&t&&t.captureSession&&t.captureSession(n)}_callExtensionMethod(e,...t){const n=A().__SENTRY__;if(n&&n.extensions&&"function"==typeof n.extensions[e])return n.extensions[e].apply(this,t);g.T&&a.vF.warn(`Extension method ${e} couldn't be found, doing nothing.`)}}function A(){return c.OW.__SENTRY__=c.OW.__SENTRY__||{extensions:{},hub:void 0},c.OW}function W(e){const t=A(),n=R(t);return Y(t,e),n}function f(){const e=A();if(e.__SENTRY__&&e.__SENTRY__.acs){const t=e.__SENTRY__.acs.getCurrentHub();if(t)return t}return function(e=A()){return t=e,!!(t&&t.__SENTRY__&&t.__SENTRY__.hub)&&!R(e).isOlderThan(Z)||Y(e,new B),R(e);var t}(e)}function V(){return f().getIsolationScope()}function v(e,t={}){const n=A();return n.__SENTRY__&&n.__SENTRY__.acs?n.__SENTRY__.acs.runWithAsyncContext(e,t):e()}function R(e){return(0,c.BY)("hub",(()=>new B),e)}function Y(e,t){return!!e&&((e.__SENTRY__=e.__SENTRY__||{}).hub=t,!0)}},741:(e,t,n)=>{"use strict";n.d(t,{g:()=>o});var i=n(1041);let s;function o(e){const t=function(e){return s?s.get(e):void 0}(e);if(!t)return;const n={};for(const[,[e,s]]of t)n[e]||(n[e]=[]),n[e].push((0,i.Ce)(s));return n}},5071:(e,t,n)=>{"use strict";n.d(t,{E1:()=>a,JD:()=>r,i_:()=>i,sy:()=>s,uT:()=>o});const i="sentry.source",s="sentry.sample_rate",o="sentry.op",r="sentry.origin",a="profile_id"},9738:(e,t,n)=>{"use strict";n.d(t,{k:()=>l,l:()=>c});var i=n(1041),s=n(7765),o=n(9071),r=n(9266),a=n(5895);function c(e,t,n){const o=t.getOptions(),{publicKey:r}=t.getDsn()||{},{segment:a}=n&&n.getUser()||{},c=(0,i.Ce)({environment:o.environment||s.U,release:o.release,user_segment:a,public_key:r,trace_id:e});return t.emit&&t.emit("createDsc",c),c}function l(e){const t=(0,o.KU)();if(!t)return{};const n=c((0,a.et)(e).trace_id||"",t,(0,o.o5)()),i=(0,r.z)(e);if(!i)return n;const s=i&&i._frozenDynamicSamplingContext;if(s)return s;const{sampleRate:l,source:g}=i.metadata;null!=l&&(n.sample_rate=`${l}`);const d=(0,a.et)(i);return g&&"url"!==g&&(n.transaction=d.description),n.sampled=String((0,a.pK)(i)),t.emit&&t.emit("createDsc",n),n}},1763:(e,t,n)=>{"use strict";n.d(t,{U:()=>B,p:()=>G});var i=n(6202),s=n(7022),o=n(6588),r=n(5895),a=n(2231),c=n(6768);let l=null;function g(){l=a.OW.onerror,a.OW.onerror=function(e,t,n,i,s){const o={column:i,error:s,line:n,msg:e,url:t};return(0,c.aj)("error",o),!(!l||l.__SENTRY_LOADER__)&&l.apply(this,arguments)},a.OW.onerror.__SENTRY_INSTRUMENTED__=!0}let d=null;function u(){d=a.OW.onunhandledrejection,a.OW.onunhandledrejection=function(e){const t=e;return(0,c.aj)("unhandledrejection",t),!(d&&!d.__SENTRY_LOADER__)||d.apply(this,arguments)},a.OW.onunhandledrejection.__SENTRY_INSTRUMENTED__=!0}var b=n(1692);let I=!1;function p(){const e=(0,b.Z7)();if(e){const t="internal_error";s.T&&i.vF.log(`[Tracing] Transaction: ${t} -> Global error occured`),e.setStatus(t)}}p.tag="sentry_tracingErrorCallback";var C=n(683),h=n(6056),m=n(9049);function y(){const e=this.getScope().getSpan();return e?{"sentry-trace":(0,r.Qh)(e)}:{}}function Z(e,t){const n=this.getClient(),o=n&&n.getOptions()||{},r=o.instrumenter||"sentry",a=e.instrumenter||"sentry";r!==a&&(s.T&&i.vF.error(`A transaction was started with instrumenter=\`${a}\`, but the SDK is configured with the \`${r}\` instrumenter.\nThe transaction will not be sampled. Please use the ${r} instrumentation to start transactions.`),e.sampled=!1);let c=new m.Z(e,this);return c=(0,h.T)(c,o,{name:e.name,parentSampled:e.parentSampled,transactionContext:e,attributes:{...e.data,...e.attributes},...t}),c.isRecording()&&c.initSpanRecorder(o._experiments&&o._experiments.maxSpans),n&&n.emit&&n.emit("startTransaction",c),c}function G(e,t,n,i,s,o,r,a=!1){const c=e.getClient(),l=c&&c.getOptions()||{};let g=new C.zX(t,e,n,i,r,s,a);return g=(0,h.T)(g,l,{name:t.name,parentSampled:t.parentSampled,transactionContext:t,attributes:{...t.data,...t.attributes},...o}),g.isRecording()&&g.initSpanRecorder(l._experiments&&l._experiments.maxSpans),c&&c.emit&&c.emit("startTransaction",g),g}function B(){const e=(0,o.EU)();e.__SENTRY__&&(e.__SENTRY__.extensions=e.__SENTRY__.extensions||{},e.__SENTRY__.extensions.startTransaction||(e.__SENTRY__.extensions.startTransaction=Z),e.__SENTRY__.extensions.traceHeaders||(e.__SENTRY__.extensions.traceHeaders=y),I||(I=!0,function(e){const t="error";(0,c.s5)(t,e),(0,c.AS)(t,g)}(p),function(e){const t="unhandledrejection";(0,c.s5)(t,e),(0,c.AS)(t,u)}(p)))}},683:(e,t,n)=>{"use strict";n.d(t,{Cq:()=>l,zX:()=>u});var i=n(6202),s=n(7567),o=n(7022),r=n(5895),a=n(7037),c=n(9049);const l={idleTimeout:1e3,finalTimeout:3e4,heartbeatInterval:5e3},g=["heartbeatFailed","idleTimeout","documentHidden","finalTimeout","externalFinish","cancelled"];class d extends a.l{constructor(e,t,n,i){super(i),this._pushActivity=e,this._popActivity=t,this.transactionSpanId=n}add(e){if(e.spanContext().spanId!==this.transactionSpanId){const t=e.end;e.end=(...n)=>(this._popActivity(e.spanContext().spanId),t.apply(e,n)),void 0===(0,r.et)(e).timestamp&&this._pushActivity(e.spanContext().spanId)}super.add(e)}}class u extends c.Z{constructor(e,t,n=l.idleTimeout,s=l.finalTimeout,r=l.heartbeatInterval,a=!1,c=!1){super(e,t),this._idleHub=t,this._idleTimeout=n,this._finalTimeout=s,this._heartbeatInterval=r,this._onScope=a,this.activities={},this._heartbeatCounter=0,this._finished=!1,this._idleTimeoutCanceledPermanently=!1,this._beforeFinishCallbacks=[],this._finishReason=g[4],this._autoFinishAllowed=!c,a&&(o.T&&i.vF.log(`Setting idle transaction on scope. Span ID: ${this.spanContext().spanId}`),t.getScope().setSpan(this)),c||this._restartIdleTimeout(),setTimeout((()=>{this._finished||(this.setStatus("deadline_exceeded"),this._finishReason=g[3],this.end())}),this._finalTimeout)}end(e){const t=(0,r.cI)(e);if(this._finished=!0,this.activities={},"ui.action.click"===this.op&&this.setAttribute("finishReason",this._finishReason),this.spanRecorder){o.T&&i.vF.log("[Tracing] finishing IdleTransaction",new Date(1e3*t).toISOString(),this.op);for(const e of this._beforeFinishCallbacks)e(this,t);this.spanRecorder.spans=this.spanRecorder.spans.filter((e=>{if(e.spanContext().spanId===this.spanContext().spanId)return!0;(0,r.et)(e).timestamp||(e.setStatus("cancelled"),e.end(t),o.T&&i.vF.log("[Tracing] cancelling span since transaction ended early",JSON.stringify(e,void 0,2)));const{start_timestamp:n,timestamp:s}=(0,r.et)(e),a=n&&n{this._finished||this._pushActivity(e)},n=e=>{this._finished||this._popActivity(e)};this.spanRecorder=new d(t,n,this.spanContext().spanId,e),o.T&&i.vF.log("Starting heartbeat"),this._pingHeartbeat()}this.spanRecorder.add(this)}cancelIdleTimeout(e,{restartOnChildSpanChange:t}={restartOnChildSpanChange:!0}){this._idleTimeoutCanceledPermanently=!1===t,this._idleTimeoutID&&(clearTimeout(this._idleTimeoutID),this._idleTimeoutID=void 0,0===Object.keys(this.activities).length&&this._idleTimeoutCanceledPermanently&&(this._finishReason=g[5],this.end(e)))}setFinishReason(e){this._finishReason=e}sendAutoFinishSignal(){this._autoFinishAllowed||(o.T&&i.vF.log("[Tracing] Received finish signal for idle transaction."),this._restartIdleTimeout(),this._autoFinishAllowed=!0)}_restartIdleTimeout(e){this.cancelIdleTimeout(),this._idleTimeoutID=setTimeout((()=>{this._finished||0!==Object.keys(this.activities).length||(this._finishReason=g[1],this.end(e))}),this._idleTimeout)}_pushActivity(e){this.cancelIdleTimeout(void 0,{restartOnChildSpanChange:!this._idleTimeoutCanceledPermanently}),o.T&&i.vF.log(`[Tracing] pushActivity: ${e}`),this.activities[e]=!0,o.T&&i.vF.log("[Tracing] new activities count",Object.keys(this.activities).length)}_popActivity(e){if(this.activities[e]&&(o.T&&i.vF.log(`[Tracing] popActivity ${e}`),delete this.activities[e],o.T&&i.vF.log("[Tracing] new activities count",Object.keys(this.activities).length)),0===Object.keys(this.activities).length){const e=(0,s.zf)();this._idleTimeoutCanceledPermanently?this._autoFinishAllowed&&(this._finishReason=g[5],this.end(e)):this._restartIdleTimeout(e+this._idleTimeout/1e3)}}_beat(){if(this._finished)return;const e=Object.keys(this.activities).join("");e===this._prevHeartbeatString?this._heartbeatCounter++:this._heartbeatCounter=1,this._prevHeartbeatString=e,this._heartbeatCounter>=3?this._autoFinishAllowed&&(o.T&&i.vF.log("[Tracing] Transaction finished because of no change for 3 heart beats"),this.setStatus("deadline_exceeded"),this._finishReason=g[0],this.end()):this._pingHeartbeat()}_pingHeartbeat(){o.T&&i.vF.log(`pinging Heartbeat -> current counter: ${this._heartbeatCounter}`),setTimeout((()=>{this._beat()}),this._heartbeatInterval)}}},6056:(e,t,n)=>{"use strict";n.d(t,{T:()=>l,v:()=>g});var i=n(6202),s=n(138),o=n(7022),r=n(5071),a=n(5177),c=n(5895);function l(e,t,n){if(!(0,a.w)(t))return e.sampled=!1,e;if(void 0!==e.sampled)return e.setAttribute(r.sy,Number(e.sampled)),e;let s;return"function"==typeof t.tracesSampler?(s=t.tracesSampler(n),e.setAttribute(r.sy,Number(s))):void 0!==n.parentSampled?s=n.parentSampled:void 0!==t.tracesSampleRate?(s=t.tracesSampleRate,e.setAttribute(r.sy,Number(s))):(s=1,e.setAttribute(r.sy,s)),g(s)?s?(e.sampled=Math.random()1)||(o.T&&i.vF.warn(`[Tracing] Given sample rate is invalid. Sample rate must be between 0 and 1. Got ${e}.`),!1)}},7037:(e,t,n)=>{"use strict";n.d(t,{L:()=>I,l:()=>b});var i=n(4902),s=n(7567),o=n(6202),r=n(1041),a=n(7022),c=n(741),l=n(5071),g=n(9266),d=n(5895),u=n(4131);class b{constructor(e=1e3){this._maxlen=e,this.spans=[]}add(e){this.spans.length>this._maxlen?e.spanRecorder=void 0:this.spans.push(e)}}class I{constructor(e={}){this._traceId=e.traceId||(0,i.eJ)(),this._spanId=e.spanId||(0,i.eJ)().substring(16),this._startTime=e.startTimestamp||(0,s.zf)(),this.tags=e.tags?{...e.tags}:{},this.data=e.data?{...e.data}:{},this.instrumenter=e.instrumenter||"sentry",this._attributes={},this.setAttributes({[l.JD]:e.origin||"manual",[l.uT]:e.op,...e.attributes}),this._name=e.name||e.description,e.parentSpanId&&(this._parentSpanId=e.parentSpanId),"sampled"in e&&(this._sampled=e.sampled),e.status&&(this._status=e.status),e.endTimestamp&&(this._endTime=e.endTimestamp),void 0!==e.exclusiveTime&&(this._exclusiveTime=e.exclusiveTime),this._measurements=e.measurements?{...e.measurements}:{}}get name(){return this._name||""}set name(e){this.updateName(e)}get description(){return this._name}set description(e){this._name=e}get traceId(){return this._traceId}set traceId(e){this._traceId=e}get spanId(){return this._spanId}set spanId(e){this._spanId=e}set parentSpanId(e){this._parentSpanId=e}get parentSpanId(){return this._parentSpanId}get sampled(){return this._sampled}set sampled(e){this._sampled=e}get attributes(){return this._attributes}set attributes(e){this._attributes=e}get startTimestamp(){return this._startTime}set startTimestamp(e){this._startTime=e}get endTimestamp(){return this._endTime}set endTimestamp(e){this._endTime=e}get status(){return this._status}set status(e){this._status=e}get op(){return this._attributes[l.uT]}set op(e){this.setAttribute(l.uT,e)}get origin(){return this._attributes[l.JD]}set origin(e){this.setAttribute(l.JD,e)}spanContext(){const{_spanId:e,_traceId:t,_sampled:n}=this;return{spanId:e,traceId:t,traceFlags:n?d.aO:d.CC}}startChild(e){const t=new I({...e,parentSpanId:this._spanId,sampled:this._sampled,traceId:this._traceId});t.spanRecorder=this.spanRecorder,t.spanRecorder&&t.spanRecorder.add(t);const n=(0,g.z)(this);if(t.transaction=n,a.T&&n){const i=`[Tracing] Starting '${e&&e.op||"< unknown op >"}' span on transaction '${(0,d.et)(t).description||"< unknown name >"}' (${n.spanContext().spanId}).`;o.vF.log(i),this._logMessage=i}return t}setTag(e,t){return this.tags={...this.tags,[e]:t},this}setData(e,t){return this.data={...this.data,[e]:t},this}setAttribute(e,t){void 0===t?delete this._attributes[e]:this._attributes[e]=t}setAttributes(e){Object.keys(e).forEach((t=>this.setAttribute(t,e[t])))}setStatus(e){return this._status=e,this}setHttpStatus(e){return(0,u.N8)(this,e),this}setName(e){this.updateName(e)}updateName(e){return this._name=e,this}isSuccess(){return"ok"===this._status}finish(e){return this.end(e)}end(e){if(this._endTime)return;const t=(0,g.z)(this);if(a.T&&t&&t.spanContext().spanId!==this._spanId){const e=this._logMessage;e&&o.vF.log(e.replace("Starting","Finishing"))}this._endTime=(0,d.cI)(e)}toTraceparent(){return(0,d.Qh)(this)}toContext(){return(0,r.Ce)({data:this._getData(),description:this._name,endTimestamp:this._endTime,op:this.op,parentSpanId:this._parentSpanId,sampled:this._sampled,spanId:this._spanId,startTimestamp:this._startTime,status:this._status,tags:this.tags,traceId:this._traceId})}updateWithContext(e){return this.data=e.data||{},this._name=e.name||e.description,this._endTime=e.endTimestamp,this.op=e.op,this._parentSpanId=e.parentSpanId,this._sampled=e.sampled,this._spanId=e.spanId||this._spanId,this._startTime=e.startTimestamp||this._startTime,this._status=e.status,this.tags=e.tags||{},this._traceId=e.traceId||this._traceId,this}getTraceContext(){return(0,d.kX)(this)}getSpanJSON(){return(0,r.Ce)({data:this._getData(),description:this._name,op:this._attributes[l.uT],parent_span_id:this._parentSpanId,span_id:this._spanId,start_timestamp:this._startTime,status:this._status,tags:Object.keys(this.tags).length>0?this.tags:void 0,timestamp:this._endTime,trace_id:this._traceId,origin:this._attributes[l.JD],_metrics_summary:(0,c.g)(this),profile_id:this._attributes[l.E1],exclusive_time:this._exclusiveTime,measurements:Object.keys(this._measurements).length>0?this._measurements:void 0})}isRecording(){return!this._endTime&&!!this._sampled}toJSON(){return this.getSpanJSON()}_getData(){const{data:e,_attributes:t}=this,n=Object.keys(e).length>0,i=Object.keys(t).length>0;if(n||i)return n&&i?{...e,...t}:n?e:t}}},4131:(e,t,n)=>{"use strict";var i;function s(e){if(e<400&&e>=100)return"ok";if(e>=400&&e<500)switch(e){case 401:return"unauthenticated";case 403:return"permission_denied";case 404:return"not_found";case 409:return"already_exists";case 413:return"failed_precondition";case 429:return"resource_exhausted";default:return"invalid_argument"}if(e>=500&&e<600)switch(e){case 501:return"unimplemented";case 503:return"unavailable";case 504:return"deadline_exceeded";default:return"internal_error"}return"unknown_error"}n.d(t,{Fp:()=>i,N8:()=>r,o6:()=>o}),function(e){e.Ok="ok",e.DeadlineExceeded="deadline_exceeded",e.Unauthenticated="unauthenticated",e.PermissionDenied="permission_denied",e.NotFound="not_found",e.ResourceExhausted="resource_exhausted",e.InvalidArgument="invalid_argument",e.Unimplemented="unimplemented",e.Unavailable="unavailable",e.InternalError="internal_error",e.UnknownError="unknown_error",e.Cancelled="cancelled",e.AlreadyExists="already_exists",e.FailedPrecondition="failed_precondition",e.Aborted="aborted",e.OutOfRange="out_of_range",e.DataLoss="data_loss"}(i||(i={}));const o=s;function r(e,t){e.setTag("http.status_code",String(t)),e.setData("http.response.status_code",t);const n=s(t);"unknown_error"!==n&&e.setStatus(n)}},9589:(e,t,n)=>{"use strict";n.d(t,{Lb:()=>C,Uk:()=>d,Lk:()=>g});var i=n(1041),s=n(6588),o=n(5895),r=n(9738),a=n(9071),c=n(138);var l=n(5177);function g(e,t){const n=b(e);return(0,s.fx)((()=>(0,a.v4)(e.scope,(i=>{const r=(0,s.BF)(),a=i.getSpan(),l=e.onlyIfParent&&!a?void 0:u(r,{parentSpan:a,spanContext:n,forceTransaction:e.forceTransaction,scope:i});return function(e,t,n=()=>{}){let i;try{i=e()}catch(e){throw t(e),n(),e}return function(e,t,n){return(0,c.Qg)(e)?e.then((e=>(n(),e)),(e=>{throw t(e),n(),e})):(n(),e)}(i,t,n)}((()=>t(l)),(()=>{if(l){const{status:e}=(0,o.et)(l);e&&"ok"!==e||l.setStatus("internal_error")}}),(()=>l&&l.end()))}))))}function d(e){if(!(0,l.w)())return;const t=b(e),n=(0,s.BF)(),i=e.scope?e.scope.getSpan():(0,a.o5)().getSpan();if(e.onlyIfParent&&!i)return;const o=(e.scope||(0,a.o5)()).clone();return u(n,{parentSpan:i,spanContext:t,forceTransaction:e.forceTransaction,scope:o})}function u(e,{parentSpan:t,spanContext:n,forceTransaction:a,scope:c}){if(!(0,l.w)())return;const g=(0,s.rm)();let d;if(t&&!a)d=t.startChild(n);else if(t){const i=(0,r.k)(t),{traceId:s,spanId:a}=t.spanContext(),c=(0,o.pK)(t);d=e.startTransaction({traceId:s,parentSpanId:a,parentSampled:c,...n,metadata:{dynamicSamplingContext:i,...n.metadata}})}else{const{traceId:t,dsc:i,parentSpanId:s,sampled:o}={...g.getPropagationContext(),...c.getPropagationContext()};d=e.startTransaction({traceId:t,parentSpanId:s,parentSampled:o,...n,metadata:{dynamicSamplingContext:i,...n.metadata}})}return c.setSpan(d),function(e,t,n){e&&((0,i.my)(e,p,n),(0,i.my)(e,I,t))}(d,c,g),d}function b(e){if(e.startTime){const t={...e};return t.startTimestamp=(0,o.cI)(e.startTime),delete t.startTime,t}return e}const I="_sentryScope",p="_sentryIsolationScope";function C(e){return{scope:e[I],isolationScope:e[p]}}},9049:(e,t,n)=>{"use strict";n.d(t,{Z:()=>b});var i=n(1041),s=n(6202),o=n(7022),r=n(6588),a=n(741),c=n(5071),l=n(5895),g=n(9738),d=n(7037),u=n(9589);class b extends d.L{constructor(e,t){super(e),this._contexts={},this._hub=t||(0,r.BF)(),this._name=e.name||"",this._metadata={...e.metadata},this._trimEnd=e.trimEnd,this.transaction=this;const n=this._metadata.dynamicSamplingContext;n&&(this._frozenDynamicSamplingContext={...n})}get name(){return this._name}set name(e){this.setName(e)}get metadata(){return{source:"custom",spanMetadata:{},...this._metadata,...this._attributes[c.i_]&&{source:this._attributes[c.i_]},...this._attributes[c.sy]&&{sampleRate:this._attributes[c.sy]}}}set metadata(e){this._metadata=e}setName(e,t="custom"){this._name=e,this.setAttribute(c.i_,t)}updateName(e){return this._name=e,this}initSpanRecorder(e=1e3){this.spanRecorder||(this.spanRecorder=new d.l(e)),this.spanRecorder.add(this)}setContext(e,t){null===t?delete this._contexts[e]:this._contexts[e]=t}setMeasurement(e,t,n=""){this._measurements[e]={value:t,unit:n}}setMetadata(e){this._metadata={...this._metadata,...e}}end(e){const t=(0,l.cI)(e),n=this._finishTransaction(t);if(n)return this._hub.captureEvent(n)}toContext(){const e=super.toContext();return(0,i.Ce)({...e,name:this._name,trimEnd:this._trimEnd})}updateWithContext(e){return super.updateWithContext(e),this._name=e.name||"",this._trimEnd=e.trimEnd,this}getDynamicSamplingContext(){return(0,g.k)(this)}setHub(e){this._hub=e}getProfileId(){if(void 0!==this._contexts&&void 0!==this._contexts.profile)return this._contexts.profile.profile_id}_finishTransaction(e){if(void 0!==this._endTime)return;this._name||(o.T&&s.vF.warn("Transaction has no name, falling back to ``."),this._name=""),super.end(e);const t=this._hub.getClient();if(t&&t.emit&&t.emit("finishTransaction",this),!0!==this._sampled)return o.T&&s.vF.log("[Tracing] Discarding transaction because its trace was not chosen to be sampled."),void(t&&t.recordDroppedEvent("sample_rate","transaction"));const n=this.spanRecorder?this.spanRecorder.spans.filter((e=>e!==this&&(0,l.et)(e).timestamp)):[];if(this._trimEnd&&n.length>0){const e=n.map((e=>(0,l.et)(e).timestamp)).filter(Boolean);this._endTime=e.reduce(((e,t)=>e>t?e:t))}const{scope:r,isolationScope:c}=(0,u.Lb)(this),{metadata:d}=this,{source:b}=d,I={contexts:{...this._contexts,trace:(0,l.kX)(this)},spans:n,start_timestamp:this._startTime,tags:this.tags,timestamp:this._endTime,transaction:this._name,type:"transaction",sdkProcessingMetadata:{...d,capturedSpanScope:r,capturedSpanIsolationScope:c,...(0,i.Ce)({dynamicSamplingContext:(0,g.k)(this)})},_metrics_summary:(0,a.g)(this),...b&&{transaction_info:{source:b}}};return Object.keys(this._measurements).length>0&&(o.T&&s.vF.log("[Measurements] Adding measurements to transaction",JSON.stringify(this._measurements,void 0,2)),I.measurements=this._measurements),o.T&&s.vF.log(`[Tracing] Finishing ${this.op} transaction: ${this._name}.`),I}}},1692:(e,t,n)=>{"use strict";n.d(t,{Z7:()=>o,nc:()=>r});var i=n(1206),s=n(6588);function o(e){return(e||(0,s.BF)()).getScope().getTransaction()}const r=i.nc},9266:(e,t,n)=>{"use strict";function i(e){return e.transaction}n.d(t,{z:()=>i})},5177:(e,t,n)=>{"use strict";n.d(t,{w:()=>s});var i=n(9071);function s(e){if("boolean"==typeof __SENTRY_TRACING__&&!__SENTRY_TRACING__)return!1;const t=(0,i.KU)(),n=e||t&&t.getOptions();return!!n&&(n.enableTracing||"tracesSampleRate"in n||"tracesSampler"in n)}},5895:(e,t,n)=>{"use strict";n.d(t,{CC:()=>r,Qh:()=>l,aO:()=>a,cI:()=>g,et:()=>u,kX:()=>c,pK:()=>b});var i=n(1041),s=n(1206),o=n(7567);const r=0,a=1;function c(e){const{spanId:t,traceId:n}=e.spanContext(),{data:s,op:o,parent_span_id:r,status:a,tags:c,origin:l}=u(e);return(0,i.Ce)({data:s,op:o,parent_span_id:r,span_id:t,status:a,tags:c,trace_id:n,origin:l})}function l(e){const{traceId:t,spanId:n}=e.spanContext(),i=b(e);return(0,s.TC)(t,n,i)}function g(e){return"number"==typeof e?d(e):Array.isArray(e)?e[0]+e[1]/1e9:e instanceof Date?d(e.getTime()):(0,o.zf)()}function d(e){return e>9999999999?e/1e3:e}function u(e){return function(e){return"function"==typeof e.getSpanJSON}(e)?e.getSpanJSON():"function"==typeof e.toJSON?e.toJSON():{}}function b(e){const{traceFlags:t}=e.spanContext();return Boolean(t&a)}},8562:(e,t,n)=>{"use strict";n.d(t,{De:()=>d,hF:()=>r,yD:()=>g});var i=n(9610),s=n(138),o=n(6202);const r="baggage",a="sentry-",c=/^sentry-/,l=8192;function g(e){if(!(0,s.Kg)(e)&&!Array.isArray(e))return;let t={};if(Array.isArray(e))t=e.reduce(((e,t)=>{const n=u(t);for(const t of Object.keys(n))e[t]=n[t];return e}),{});else{if(!e)return;t=u(e)}const n=Object.entries(t).reduce(((e,[t,n])=>(t.match(c)&&(e[t.slice(a.length)]=n),e)),{});return Object.keys(n).length>0?n:void 0}function d(e){if(e)return function(e){if(0!==Object.keys(e).length)return Object.entries(e).reduce(((e,[t,n],s)=>{const r=`${encodeURIComponent(t)}=${encodeURIComponent(n)}`,a=0===s?r:`${e},${r}`;return a.length>l?(i.T&&o.vF.warn(`Not adding key: ${t} with val: ${n} to baggage header due to exceeding baggage size limits.`),e):a}),"")}(Object.entries(e).reduce(((e,[t,n])=>(n&&(e[`${a}${t}`]=n),e)),{}))}function u(e){return e.split(",").map((e=>e.split("=").map((e=>decodeURIComponent(e.trim()))))).reduce(((e,[t,n])=>(e[t]=n,e)),{})}},9610:(e,t,n)=>{"use strict";n.d(t,{T:()=>i});const i="undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__},6768:(e,t,n)=>{"use strict";n.d(t,{AS:()=>l,aj:()=>g,s5:()=>c});var i=n(9610),s=n(6202),o=n(8231);const r={},a={};function c(e,t){r[e]=r[e]||[],r[e].push(t)}function l(e,t){a[e]||(t(),a[e]=!0)}function g(e,t){const n=e&&r[e];if(n)for(const r of n)try{r(t)}catch(t){i.T&&s.vF.error(`Error while triggering instrumentation handler.\nType: ${e}\nName: ${(0,o.qQ)(r)}\nError:`,t)}}},138:(e,t,n)=>{"use strict";n.d(t,{Kg:()=>o,Qd:()=>r,Qg:()=>c,gd:()=>a,tH:()=>g,yr:()=>l});const i=Object.prototype.toString;function s(e,t){return i.call(e)===`[object ${t}]`}function o(e){return s(e,"String")}function r(e){return s(e,"Object")}function a(e){return s(e,"RegExp")}function c(e){return Boolean(e&&e.then&&"function"==typeof e.then)}function l(e){return"number"==typeof e&&e!=e}function g(e,t){try{return e instanceof t}catch(e){return!1}}},6202:(e,t,n)=>{"use strict";n.d(t,{pq:()=>a,vF:()=>c});var i=n(9610),s=n(2231);const o=["debug","info","warn","error","log","assert","trace"],r={};function a(e){if(!("console"in s.OW))return e();const t=s.OW.console,n={},i=Object.keys(r);i.forEach((e=>{const i=r[e];n[e]=t[e],t[e]=i}));try{return e()}finally{i.forEach((e=>{t[e]=n[e]}))}}const c=function(){let e=!1;const t={enable:()=>{e=!0},disable:()=>{e=!1},isEnabled:()=>e};return i.T?o.forEach((n=>{t[n]=(...t)=>{e&&a((()=>{s.OW.console[n](`Sentry Logger [${n}]:`,...t)}))}})):o.forEach((e=>{t[e]=()=>{}})),t}()},4902:(e,t,n)=>{"use strict";n.d(t,{eJ:()=>s,k9:()=>o});var i=n(2231);function s(){const e=i.OW,t=e.crypto||e.msCrypto;let n=()=>16*Math.random();try{if(t&&t.randomUUID)return t.randomUUID().replace(/-/g,"");t&&t.getRandomValues&&(n=()=>{const e=new Uint8Array(1);return t.getRandomValues(e),e[0]})}catch(e){}return([1e7]+1e3+4e3+8e3+1e11).replace(/[018]/g,(e=>(e^(15&n())>>e/4).toString(16)))}function o(e){return Array.isArray(e)?e:[e]}},8560:(e,t,n)=>{"use strict";function i(){return!("undefined"!=typeof __SENTRY_BROWSER_BUNDLE__&&__SENTRY_BROWSER_BUNDLE__)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0)}function s(e,t){return e.require(t)}function o(t){let n;try{n=s(e,t)}catch(e){}try{const{cwd:i}=s(e,"process");n=s(e,`${i()}/node_modules/${t}`)}catch(e){}return n}n.d(t,{fj:()=>s,wD:()=>i,Vw:()=>o}),e=n.hmd(e)},1041:(e,t,n)=>{"use strict";n.d(t,{Ce:()=>c,GS:()=>r,my:()=>a});var i=n(9610),s=n(138),o=n(6202);function r(e,t,n){if(!(t in e))return;const i=e[t],s=n(i);"function"==typeof s&&function(e,t){try{const n=t.prototype||{};e.prototype=t.prototype=n,a(e,"__sentry_original__",t)}catch(e){}}(s,i),e[t]=s}function a(e,t,n){try{Object.defineProperty(e,t,{value:n,writable:!0,configurable:!0})}catch(n){i.T&&o.vF.log(`Failed to add non-enumerable property "${t}" to object`,e)}}function c(e){return l(e,new Map)}function l(e,t){if(function(e){if(!(0,s.Qd)(e))return!1;try{const t=Object.getPrototypeOf(e).constructor.name;return!t||"Object"===t}catch(e){return!0}}(e)){const n=t.get(e);if(void 0!==n)return n;const i={};t.set(e,i);for(const n of Object.keys(e))void 0!==e[n]&&(i[n]=l(e[n],t));return i}if(Array.isArray(e)){const n=t.get(e);if(void 0!==n)return n;const i=[];return t.set(e,i),e.forEach((e=>{i.push(l(e,t))})),i}return e}},8231:(e,t,n)=>{"use strict";n.d(t,{qQ:()=>s});const i="";function s(e){try{return e&&"function"==typeof e&&e.name||i}catch(e){return i}}},7567:(e,t,n)=>{"use strict";n.d(t,{k3:()=>c,lu:()=>o,zf:()=>r});var i=n(2231);const s=1e3;function o(){return Date.now()/s}const r=function(){const{performance:e}=i.OW;if(!e||!e.now)return o;const t=Date.now()-e.now(),n=null==e.timeOrigin?t:e.timeOrigin;return()=>(n+e.now())/s}();let a;const c=(()=>{const{performance:e}=i.OW;if(!e||!e.now)return void(a="none");const t=36e5,n=e.now(),s=Date.now(),o=e.timeOrigin?Math.abs(e.timeOrigin+n-s):t,r=o{"use strict";n.d(t,{MI:()=>o,TC:()=>c,kM:()=>a,nc:()=>r});var i=n(8562),s=n(4902);const o=new RegExp("^[ \\t]*([0-9a-f]{32})?-?([0-9a-f]{16})?-?([01])?[ \\t]*$");function r(e){if(!e)return;const t=e.match(o);if(!t)return;let n;return"1"===t[3]?n=!0:"0"===t[3]&&(n=!1),{traceId:t[1],parentSampled:n,parentSpanId:t[2]}}function a(e,t){const n=r(e),o=(0,i.yD)(t),{traceId:a,parentSpanId:c,parentSampled:l}=n||{};return n?{traceId:a||(0,s.eJ)(),parentSpanId:c||(0,s.eJ)().substring(16),spanId:(0,s.eJ)().substring(16),sampled:l,dsc:o||{}}:{traceId:a||(0,s.eJ)(),spanId:(0,s.eJ)().substring(16)}}function c(e=(0,s.eJ)(),t=(0,s.eJ)().substring(16),n){let i="";return void 0!==n&&(i=n?"-1":"-0"),`${e}-${t}${i}`}},2231:(e,t,n)=>{"use strict";function i(e){return e&&e.Math==Math?e:void 0}n.d(t,{BY:()=>r,OW:()=>s,VZ:()=>o});const s="object"==typeof globalThis&&i(globalThis)||"object"==typeof window&&i(window)||"object"==typeof self&&i(self)||"object"==typeof global&&i(global)||function(){return this}()||{};function o(){return s}function r(e,t,n){const i=n||s,o=i.__SENTRY__=i.__SENTRY__||{};return o[e]||(o[e]=t())}},2967:(e,t,n)=>{"use strict";n.d(t,{U:()=>i});const i="production"},2220:(e,t,n)=>{"use strict";n.d(t,{T:()=>i});const i="undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__},2531:(e,t,n)=>{"use strict";n.d(t,{jB:()=>g,lG:()=>c,lb:()=>l});var i=n(6341),s=n(690),o=n(7412),r=n(3816),a=n(2220);function c(){return(0,i.BY)("globalEventProcessors",(()=>[]))}function l(e){c().push(e)}function g(e,t,n,i=0){return new s.T2(((s,c)=>{const l=e[i];if(null===t||"function"!=typeof l)s(t);else{const d=l({...t},n);a.T&&l.id&&null===d&&o.vF.log(`Event processor "${l.id}" dropped event`),(0,r.Qg)(d)?d.then((t=>g(e,t,n,i+1).then(s))).then(null,c):g(e,d,n,i+1).then(s).then(null,c)}}))}},3741:(e,t,n)=>{"use strict";n.d(t,{Cp:()=>b,Dp:()=>w,J0:()=>F,J5:()=>J,KU:()=>N,NA:()=>B,PN:()=>C,Q:()=>S,SE:()=>R,T$:()=>Y,VN:()=>H,Wt:()=>G,ZQ:()=>h,bX:()=>X,cx:()=>y,gV:()=>A,hb:()=>V,ky:()=>k,l7:()=>Z,nb:()=>v,o:()=>m,o5:()=>K,r:()=>p,rB:()=>f,v4:()=>W,wd:()=>I});var i=n(7412),s=n(6936),o=n(9297),r=n(3816),a=n(6341),c=n(2967),l=n(2220),g=n(6641),d=n(7058),u=n(9475);function b(e,t){return(0,g.BF)().captureException(e,(0,u.li)(t))}function I(e,t){const n="string"==typeof t?t:void 0,i="string"!=typeof t?{captureContext:t}:void 0;return(0,g.BF)().captureMessage(e,n,i)}function p(e,t){return(0,g.BF)().captureEvent(e,t)}function C(e){(0,g.BF)().configureScope(e)}function h(e,t){(0,g.BF)().addBreadcrumb(e,t)}function m(e,t){(0,g.BF)().setContext(e,t)}function y(e){(0,g.BF)().setExtras(e)}function Z(e,t){(0,g.BF)().setExtra(e,t)}function G(e){(0,g.BF)().setTags(e)}function B(e,t){(0,g.BF)().setTag(e,t)}function A(e){(0,g.BF)().setUser(e)}function W(...e){const t=(0,g.BF)();if(2===e.length){const[n,i]=e;return n?t.withScope((()=>(t.getStackTop().scope=n,i(n)))):t.withScope(i)}return t.withScope(e[0])}function f(e){return(0,g.fx)((()=>e((0,g.rm)())))}function V(e,t){return W((n=>(n.setSpan(e),t(n))))}function v(e,t){return(0,g.BF)().startTransaction({...e},t)}function R(e,t){const n=K(),o=N();if(o){if(o.captureCheckIn)return o.captureCheckIn(e,t,n);l.T&&i.vF.warn("Cannot capture check-in. Client does not support sending check-ins.")}else l.T&&i.vF.warn("Cannot capture check-in. No client defined.");return(0,s.eJ)()}function Y(e,t,n){const i=R({monitorSlug:e,status:"in_progress"},n),s=(0,o.zf)();function a(t){R({monitorSlug:e,status:t,checkInId:i,duration:(0,o.zf)()-s})}let c;try{c=t()}catch(e){throw a("error"),e}return(0,r.Qg)(c)?Promise.resolve(c).then((()=>{a("ok")}),(()=>{a("error")})):a("ok"),c}async function X(e){const t=N();return t?t.flush(e):(l.T&&i.vF.warn("Cannot flush events. No client defined."),Promise.resolve(!1))}async function H(e){const t=N();return t?t.close(e):(l.T&&i.vF.warn("Cannot flush events and disable SDK. No client defined."),Promise.resolve(!1))}function S(){return(0,g.BF)().lastEventId()}function N(){return(0,g.BF)().getClient()}function w(){return!!N()}function K(){return(0,g.BF)().getScope()}function F(e){const t=N(),n=(0,g.rm)(),i=K(),{release:s,environment:o=c.U}=t&&t.getOptions()||{},{userAgent:r}=a.OW.navigator||{},l=(0,d.fj)({release:s,environment:o,user:i.getUser()||n.getUser(),...r&&{userAgent:r},...e}),u=n.getSession();return u&&"ok"===u.status&&(0,d.qO)(u,{status:"exited"}),k(),n.setSession(l),i.setSession(l),l}function k(){const e=(0,g.rm)(),t=K(),n=t.getSession()||e.getSession();n&&(0,d.Vu)(n),_(),e.setSession(),t.setSession()}function _(){const e=(0,g.rm)(),t=K(),n=N(),i=t.getSession()||e.getSession();i&&n&&n.captureSession&&n.captureSession(i)}function J(e=!1){e?k():_()}},6641:(e,t,n)=>{"use strict";n.d(t,{BF:()=>m,EU:()=>C,Me:()=>f,TF:()=>G,YZ:()=>p,fx:()=>A,gM:()=>h,lq:()=>V,nX:()=>B,rm:()=>y});var i=n(3816),s=n(6936),o=n(9297),r=n(7412),a=n(6341),c=n(2967),l=n(2220),g=n(2486),d=n(7058),u=n(7986);const b=parseFloat(u.M),I=100;class p{constructor(e,t,n,i=b){let s,o;this._version=i,t?s=t:(s=new g.HG,s.setClient(e)),n?o=n:(o=new g.HG,o.setClient(e)),this._stack=[{scope:s}],e&&this.bindClient(e),this._isolationScope=o}isOlderThan(e){return this._version(this.popScope(),e)),(e=>{throw this.popScope(),e})):(this.popScope(),n)}getClient(){return this.getStackTop().client}getScope(){return this.getStackTop().scope}getIsolationScope(){return this._isolationScope}getStack(){return this._stack}getStackTop(){return this._stack[this._stack.length-1]}captureException(e,t){const n=this._lastEventId=t&&t.event_id?t.event_id:(0,s.eJ)(),i=new Error("Sentry syntheticException");return this.getScope().captureException(e,{originalException:e,syntheticException:i,...t,event_id:n}),n}captureMessage(e,t,n){const i=this._lastEventId=n&&n.event_id?n.event_id:(0,s.eJ)(),o=new Error(e);return this.getScope().captureMessage(e,t,{originalException:e,syntheticException:o,...n,event_id:i}),i}captureEvent(e,t){const n=t&&t.event_id?t.event_id:(0,s.eJ)();return e.type||(this._lastEventId=n),this.getScope().captureEvent(e,{...t,event_id:n}),n}lastEventId(){return this._lastEventId}addBreadcrumb(e,t){const{scope:n,client:i}=this.getStackTop();if(!i)return;const{beforeBreadcrumb:s=null,maxBreadcrumbs:a=I}=i.getOptions&&i.getOptions()||{};if(a<=0)return;const c={timestamp:(0,o.lu)(),...e},l=s?(0,r.pq)((()=>s(c,t))):c;null!==l&&(i.emit&&i.emit("beforeAddBreadcrumb",l,t),n.addBreadcrumb(l,a))}setUser(e){this.getScope().setUser(e),this.getIsolationScope().setUser(e)}setTags(e){this.getScope().setTags(e),this.getIsolationScope().setTags(e)}setExtras(e){this.getScope().setExtras(e),this.getIsolationScope().setExtras(e)}setTag(e,t){this.getScope().setTag(e,t),this.getIsolationScope().setTag(e,t)}setExtra(e,t){this.getScope().setExtra(e,t),this.getIsolationScope().setExtra(e,t)}setContext(e,t){this.getScope().setContext(e,t),this.getIsolationScope().setContext(e,t)}configureScope(e){const{scope:t,client:n}=this.getStackTop();n&&e(t)}run(e){const t=h(this);try{e(this)}finally{h(t)}}getIntegration(e){const t=this.getClient();if(!t)return null;try{return t.getIntegration(e)}catch(t){return l.T&&r.vF.warn(`Cannot retrieve integration ${e.id} from the current Hub`),null}}startTransaction(e,t){const n=this._callExtensionMethod("startTransaction",e,t);return l.T&&!n&&(this.getClient()?r.vF.warn("Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init':\nSentry.addTracingExtensions();\nSentry.init({...});\n"):r.vF.warn("Tracing extension 'startTransaction' is missing. You should 'init' the SDK before calling 'startTransaction'")),n}traceHeaders(){return this._callExtensionMethod("traceHeaders")}captureSession(e=!1){if(e)return this.endSession();this._sendSessionUpdate()}endSession(){const e=this.getStackTop().scope,t=e.getSession();t&&(0,d.Vu)(t),this._sendSessionUpdate(),e.setSession()}startSession(e){const{scope:t,client:n}=this.getStackTop(),{release:i,environment:s=c.U}=n&&n.getOptions()||{},{userAgent:o}=a.OW.navigator||{},r=(0,d.fj)({release:i,environment:s,user:t.getUser(),...o&&{userAgent:o},...e}),l=t.getSession&&t.getSession();return l&&"ok"===l.status&&(0,d.qO)(l,{status:"exited"}),this.endSession(),t.setSession(r),r}shouldSendDefaultPii(){const e=this.getClient(),t=e&&e.getOptions();return Boolean(t&&t.sendDefaultPii)}_sendSessionUpdate(){const{scope:e,client:t}=this.getStackTop(),n=e.getSession();n&&t&&t.captureSession&&t.captureSession(n)}_callExtensionMethod(e,...t){const n=C().__SENTRY__;if(n&&n.extensions&&"function"==typeof n.extensions[e])return n.extensions[e].apply(this,t);l.T&&r.vF.warn(`Extension method ${e} couldn't be found, doing nothing.`)}}function C(){return a.OW.__SENTRY__=a.OW.__SENTRY__||{extensions:{},hub:void 0},a.OW}function h(e){const t=C(),n=f(t);return V(t,e),n}function m(){const e=C();if(e.__SENTRY__&&e.__SENTRY__.acs){const t=e.__SENTRY__.acs.getCurrentHub();if(t)return t}return Z(e)}function y(){return m().getIsolationScope()}function Z(e=C()){return W(e)&&!f(e).isOlderThan(b)||V(e,new p),f(e)}function G(e,t=Z()){if(!W(e)||f(e).isOlderThan(b)){const n=t.getClient(),i=t.getScope(),s=t.getIsolationScope();V(e,new p(n,i.clone(),s.clone()))}}function B(e){const t=C();t.__SENTRY__=t.__SENTRY__||{},t.__SENTRY__.acs=e}function A(e,t={}){const n=C();return n.__SENTRY__&&n.__SENTRY__.acs?n.__SENTRY__.acs.runWithAsyncContext(e,t):e()}function W(e){return!!(e&&e.__SENTRY__&&e.__SENTRY__.hub)}function f(e){return(0,a.BY)("hub",(()=>new p),e)}function V(e,t){return!!e&&((e.__SENTRY__=e.__SENTRY__||{}).hub=t,!0)}},5836:(e,t,n)=>{"use strict";n.d(t,{F:()=>p,P$:()=>d,Q8:()=>I,_C:()=>C,lc:()=>u,mH:()=>g,qm:()=>b});var i=n(6936),s=n(7412),o=n(2220),r=n(2531),a=n(3741),c=n(6641);const l=[];function g(e){const t=e.defaultIntegrations||[],n=e.integrations;let s;t.forEach((e=>{e.isDefaultInstance=!0})),s=Array.isArray(n)?[...t,...n]:"function"==typeof n?(0,i.k9)(n(t)):t;const o=function(e){const t={};return e.forEach((e=>{const{name:n}=e,i=t[n];i&&!i.isDefaultInstance&&e.isDefaultInstance||(t[n]=e)})),Object.keys(t).map((e=>t[e]))}(s),r=function(e){for(let t=0;t{t&&b(e,t,n)})),n}function u(e,t){for(const n of t)n&&n.afterAllSetup&&n.afterAllSetup(e)}function b(e,t,n){if(n[t.name])o.T&&s.vF.log(`Integration skipped because it was already installed: ${t.name}`);else{if(n[t.name]=t,-1===l.indexOf(t.name)&&(t.setupOnce(r.lb,c.BF),l.push(t.name)),t.setup&&"function"==typeof t.setup&&t.setup(e),e.on&&"function"==typeof t.preprocessEvent){const n=t.preprocessEvent.bind(t);e.on("preprocessEvent",((t,i)=>n(t,i,e)))}if(e.addEventProcessor&&"function"==typeof t.processEvent){const n=t.processEvent.bind(t),i=Object.assign(((t,i)=>n(t,i,e)),{id:t.name});e.addEventProcessor(i)}o.T&&s.vF.log(`Integration installed: ${t.name}`)}}function I(e){const t=(0,a.KU)();t&&t.addIntegration?t.addIntegration(e):o.T&&s.vF.warn(`Cannot add integration "${e.name}" because no SDK Client is available.`)}function p(e,t){return Object.assign((function(...e){return t(...e)}),{id:e})}function C(e){return e}},2486:(e,t,n)=>{"use strict";n.d(t,{HG:()=>d,m6:()=>u});var i=n(3816),s=n(9297),o=n(6936),r=n(7412),a=n(2531),c=n(7058),l=n(1535);let g;class d{constructor(){this._notifyingListeners=!1,this._scopeListeners=[],this._eventProcessors=[],this._breadcrumbs=[],this._attachments=[],this._user={},this._tags={},this._extra={},this._contexts={},this._sdkProcessingMetadata={},this._propagationContext=b()}static clone(e){return e?e.clone():new d}clone(){const e=new d;return e._breadcrumbs=[...this._breadcrumbs],e._tags={...this._tags},e._extra={...this._extra},e._contexts={...this._contexts},e._user=this._user,e._level=this._level,e._span=this._span,e._session=this._session,e._transactionName=this._transactionName,e._fingerprint=this._fingerprint,e._eventProcessors=[...this._eventProcessors],e._requestSession=this._requestSession,e._attachments=[...this._attachments],e._sdkProcessingMetadata={...this._sdkProcessingMetadata},e._propagationContext={...this._propagationContext},e._client=this._client,e}setClient(e){this._client=e}getClient(){return this._client}addScopeListener(e){this._scopeListeners.push(e)}addEventProcessor(e){return this._eventProcessors.push(e),this}setUser(e){return this._user=e||{email:void 0,id:void 0,ip_address:void 0,segment:void 0,username:void 0},this._session&&(0,c.qO)(this._session,{user:e}),this._notifyScopeListeners(),this}getUser(){return this._user}getRequestSession(){return this._requestSession}setRequestSession(e){return this._requestSession=e,this}setTags(e){return this._tags={...this._tags,...e},this._notifyScopeListeners(),this}setTag(e,t){return this._tags={...this._tags,[e]:t},this._notifyScopeListeners(),this}setExtras(e){return this._extra={...this._extra,...e},this._notifyScopeListeners(),this}setExtra(e,t){return this._extra={...this._extra,[e]:t},this._notifyScopeListeners(),this}setFingerprint(e){return this._fingerprint=e,this._notifyScopeListeners(),this}setLevel(e){return this._level=e,this._notifyScopeListeners(),this}setTransactionName(e){return this._transactionName=e,this._notifyScopeListeners(),this}setContext(e,t){return null===t?delete this._contexts[e]:this._contexts[e]=t,this._notifyScopeListeners(),this}setSpan(e){return this._span=e,this._notifyScopeListeners(),this}getSpan(){return this._span}getTransaction(){const e=this._span;return e&&e.transaction}setSession(e){return e?this._session=e:delete this._session,this._notifyScopeListeners(),this}getSession(){return this._session}update(e){if(!e)return this;const t="function"==typeof e?e(this):e;if(t instanceof d){const e=t.getScopeData();this._tags={...this._tags,...e.tags},this._extra={...this._extra,...e.extra},this._contexts={...this._contexts,...e.contexts},e.user&&Object.keys(e.user).length&&(this._user=e.user),e.level&&(this._level=e.level),e.fingerprint.length&&(this._fingerprint=e.fingerprint),t.getRequestSession()&&(this._requestSession=t.getRequestSession()),e.propagationContext&&(this._propagationContext=e.propagationContext)}else if((0,i.Qd)(t)){const t=e;this._tags={...this._tags,...t.tags},this._extra={...this._extra,...t.extra},this._contexts={...this._contexts,...t.contexts},t.user&&(this._user=t.user),t.level&&(this._level=t.level),t.fingerprint&&(this._fingerprint=t.fingerprint),t.requestSession&&(this._requestSession=t.requestSession),t.propagationContext&&(this._propagationContext=t.propagationContext)}return this}clear(){return this._breadcrumbs=[],this._tags={},this._extra={},this._user={},this._contexts={},this._level=void 0,this._transactionName=void 0,this._fingerprint=void 0,this._requestSession=void 0,this._span=void 0,this._session=void 0,this._notifyScopeListeners(),this._attachments=[],this._propagationContext=b(),this}addBreadcrumb(e,t){const n="number"==typeof t?t:100;if(n<=0)return this;const i={timestamp:(0,s.lu)(),...e},o=this._breadcrumbs;return o.push(i),this._breadcrumbs=o.length>n?o.slice(-n):o,this._notifyScopeListeners(),this}getLastBreadcrumb(){return this._breadcrumbs[this._breadcrumbs.length-1]}clearBreadcrumbs(){return this._breadcrumbs=[],this._notifyScopeListeners(),this}addAttachment(e){return this._attachments.push(e),this}getAttachments(){return this.getScopeData().attachments}clearAttachments(){return this._attachments=[],this}getScopeData(){const{_breadcrumbs:e,_attachments:t,_contexts:n,_tags:i,_extra:s,_user:o,_level:r,_fingerprint:a,_eventProcessors:c,_propagationContext:l,_sdkProcessingMetadata:g,_transactionName:d,_span:u}=this;return{breadcrumbs:e,attachments:t,contexts:n,tags:i,extra:s,user:o,level:r,fingerprint:a||[],eventProcessors:c,propagationContext:l,sdkProcessingMetadata:g,transactionName:d,span:u}}applyToEvent(e,t={},n=[]){(0,l.e2)(e,this.getScopeData());const i=[...n,...(0,a.lG)(),...this._eventProcessors];return(0,a.jB)(i,e,t)}setSDKProcessingMetadata(e){return this._sdkProcessingMetadata={...this._sdkProcessingMetadata,...e},this}setPropagationContext(e){return this._propagationContext=e,this}getPropagationContext(){return this._propagationContext}captureException(e,t){const n=t&&t.event_id?t.event_id:(0,o.eJ)();if(!this._client)return r.vF.warn("No client configured on scope - will not capture exception!"),n;const i=new Error("Sentry syntheticException");return this._client.captureException(e,{originalException:e,syntheticException:i,...t,event_id:n},this),n}captureMessage(e,t,n){const i=n&&n.event_id?n.event_id:(0,o.eJ)();if(!this._client)return r.vF.warn("No client configured on scope - will not capture message!"),i;const s=new Error(e);return this._client.captureMessage(e,t,{originalException:e,syntheticException:s,...n,event_id:i},this),i}captureEvent(e,t){const n=t&&t.event_id?t.event_id:(0,o.eJ)();return this._client?(this._client.captureEvent(e,{...t,event_id:n},this),n):(r.vF.warn("No client configured on scope - will not capture event!"),n)}_notifyScopeListeners(){this._notifyingListeners||(this._notifyingListeners=!0,this._scopeListeners.forEach((e=>{e(this)})),this._notifyingListeners=!1)}}function u(){return g||(g=new d),g}function b(){return{traceId:(0,o.eJ)(),spanId:(0,o.eJ)().substring(16)}}},7058:(e,t,n)=>{"use strict";n.d(t,{Vu:()=>c,fj:()=>r,qO:()=>a});var i=n(9297),s=n(6936),o=n(4022);function r(e){const t=(0,i.zf)(),n={sid:(0,s.eJ)(),init:!0,timestamp:t,started:t,duration:0,status:"ok",errors:0,ignoreDuration:!1,toJSON:()=>function(e){return(0,o.Ce)({sid:`${e.sid}`,init:e.init,started:new Date(1e3*e.started).toISOString(),timestamp:new Date(1e3*e.timestamp).toISOString(),status:e.status,errors:e.errors,did:"number"==typeof e.did||"string"==typeof e.did?`${e.did}`:void 0,duration:e.duration,abnormal_mechanism:e.abnormal_mechanism,attrs:{release:e.release,environment:e.environment,ip_address:e.ipAddress,user_agent:e.userAgent}})}(n)};return e&&a(n,e),n}function a(e,t={}){if(t.user&&(!e.ipAddress&&t.user.ip_address&&(e.ipAddress=t.user.ip_address),e.did||t.did||(e.did=t.user.id||t.user.email||t.user.username)),e.timestamp=t.timestamp||(0,i.zf)(),t.abnormal_mechanism&&(e.abnormal_mechanism=t.abnormal_mechanism),t.ignoreDuration&&(e.ignoreDuration=t.ignoreDuration),t.sid&&(e.sid=32===t.sid.length?t.sid:(0,s.eJ)()),void 0!==t.init&&(e.init=t.init),!e.did&&t.did&&(e.did=`${t.did}`),"number"==typeof t.started&&(e.started=t.started),e.ignoreDuration)e.duration=void 0;else if("number"==typeof t.duration)e.duration=t.duration;else{const t=e.timestamp-e.started;e.duration=t>=0?t:0}t.release&&(e.release=t.release),t.environment&&(e.environment=t.environment),!e.ipAddress&&t.ipAddress&&(e.ipAddress=t.ipAddress),!e.userAgent&&t.userAgent&&(e.userAgent=t.userAgent),"number"==typeof t.errors&&(e.errors=t.errors),t.status&&(e.status=t.status)}function c(e,t){let n={};t?n={status:t}:"ok"===e.status&&(n={status:"exited"}),a(e,n)}},5452:(e,t,n)=>{"use strict";n.d(t,{k:()=>l,l:()=>c});var i=n(4022),s=n(2967),o=n(3741),r=n(4636),a=n(3445);function c(e,t,n){const o=t.getOptions(),{publicKey:r}=t.getDsn()||{},{segment:a}=n&&n.getUser()||{},c=(0,i.Ce)({environment:o.environment||s.U,release:o.release,user_segment:a,public_key:r,trace_id:e});return t.emit&&t.emit("createDsc",c),c}function l(e){const t=(0,o.KU)();if(!t)return{};const n=c((0,a.et)(e).trace_id||"",t,(0,o.o5)()),i=(0,r.z)(e);if(!i)return n;const s=i&&i._frozenDynamicSamplingContext;if(s)return s;const{sampleRate:l,source:g}=i.metadata;null!=l&&(n.sample_rate=`${l}`);const d=(0,a.et)(i);return g&&"url"!==g&&(n.transaction=d.description),n.sampled=String((0,a.pK)(i)),t.emit&&t.emit("createDsc",n),n}},1535:(e,t,n)=>{"use strict";n.d(t,{Rg:()=>l,e2:()=>c});var i=n(4022),s=n(6936),o=n(5452),r=n(4636),a=n(3445);function c(e,t){const{fingerprint:n,span:c,breadcrumbs:l,sdkProcessingMetadata:g}=t;!function(e,t){const{extra:n,tags:s,user:o,contexts:r,level:a,transactionName:c}=t,l=(0,i.Ce)(n);l&&Object.keys(l).length&&(e.extra={...l,...e.extra});const g=(0,i.Ce)(s);g&&Object.keys(g).length&&(e.tags={...g,...e.tags});const d=(0,i.Ce)(o);d&&Object.keys(d).length&&(e.user={...d,...e.user});const u=(0,i.Ce)(r);u&&Object.keys(u).length&&(e.contexts={...u,...e.contexts}),a&&(e.level=a),c&&(e.transaction=c)}(e,t),c&&function(e,t){e.contexts={trace:(0,a.kX)(t),...e.contexts};const n=(0,r.z)(t);if(n){e.sdkProcessingMetadata={dynamicSamplingContext:(0,o.k)(t),...e.sdkProcessingMetadata};const i=(0,a.et)(n).description;i&&(e.tags={transaction:i,...e.tags})}}(e,c),function(e,t){e.fingerprint=e.fingerprint?(0,s.k9)(e.fingerprint):[],t&&(e.fingerprint=e.fingerprint.concat(t)),e.fingerprint&&!e.fingerprint.length&&delete e.fingerprint}(e,n),function(e,t){const n=[...e.breadcrumbs||[],...t];e.breadcrumbs=n.length?n:void 0}(e,l),function(e,t){e.sdkProcessingMetadata={...e.sdkProcessingMetadata,...t}}(e,g)}function l(e,t){const{extra:n,tags:i,user:s,contexts:o,level:r,sdkProcessingMetadata:a,breadcrumbs:c,fingerprint:l,eventProcessors:d,attachments:u,propagationContext:b,transactionName:I,span:p}=t;g(e,"extra",n),g(e,"tags",i),g(e,"user",s),g(e,"contexts",o),g(e,"sdkProcessingMetadata",a),r&&(e.level=r),I&&(e.transactionName=I),p&&(e.span=p),c.length&&(e.breadcrumbs=[...e.breadcrumbs,...c]),l.length&&(e.fingerprint=[...e.fingerprint,...l]),d.length&&(e.eventProcessors=[...e.eventProcessors,...d]),u.length&&(e.attachments=[...e.attachments,...u]),e.propagationContext={...e.propagationContext,...b}}function g(e,t,n){if(n&&Object.keys(n).length){e[t]={...e[t]};for(const i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[t][i]=n[i])}}},4636:(e,t,n)=>{"use strict";function i(e){return e.transaction}n.d(t,{z:()=>i})},9475:(e,t,n)=>{"use strict";n.d(t,{li:()=>p,mG:()=>b});var i=n(6936),s=n(9297),o=n(9653),r=n(6341),a=n(2181),c=n(2967),l=n(2531),g=n(2486),d=n(1535),u=n(3445);function b(e,t,n,b,p,C){const{normalizeDepth:h=3,normalizeMaxBreadth:m=1e3}=e,y={...t,event_id:t.event_id||n.event_id||(0,i.eJ)(),timestamp:t.timestamp||(0,s.lu)()},Z=n.integrations||e.integrations.map((e=>e.name));!function(e,t){const{environment:n,release:i,dist:s,maxValueLength:r=250}=t;"environment"in e||(e.environment="environment"in t?n:c.U),void 0===e.release&&void 0!==i&&(e.release=i),void 0===e.dist&&void 0!==s&&(e.dist=s),e.message&&(e.message=(0,o.xv)(e.message,r));const a=e.exception&&e.exception.values&&e.exception.values[0];a&&a.value&&(a.value=(0,o.xv)(a.value,r));const l=e.request;l&&l.url&&(l.url=(0,o.xv)(l.url,r))}(y,e),function(e,t){t.length>0&&(e.sdk=e.sdk||{},e.sdk.integrations=[...e.sdk.integrations||[],...t])}(y,Z),void 0===t.type&&function(e,t){const n=r.OW._sentryDebugIds;if(!n)return;let i;const s=I.get(t);s?i=s:(i=new Map,I.set(t,i));const o=Object.keys(n).reduce(((e,s)=>{let o;const r=i.get(s);r?o=r:(o=t(s),i.set(s,o));for(let t=o.length-1;t>=0;t--){const i=o[t];if(i.filename){e[i.filename]=n[s];break}}return e}),{});try{e.exception.values.forEach((e=>{e.stacktrace.frames.forEach((e=>{e.filename&&(e.debug_id=o[e.filename])}))}))}catch(e){}}(y,e.stackParser);const G=function(e,t){if(!t)return e;const n=e?e.clone():new g.HG;return n.update(t),n}(b,n.captureContext);n.mechanism&&(0,i.M6)(y,n.mechanism);const B=p&&p.getEventProcessors?p.getEventProcessors():[],A=(0,g.m6)().getScopeData();if(C){const e=C.getScopeData();(0,d.Rg)(A,e)}if(G){const e=G.getScopeData();(0,d.Rg)(A,e)}const W=[...n.attachments||[],...A.attachments];W.length&&(n.attachments=W),(0,d.e2)(y,A);const f=[...B,...(0,l.lG)(),...A.eventProcessors];return(0,l.jB)(f,y,n).then((e=>(e&&function(e){const t={};try{e.exception.values.forEach((e=>{e.stacktrace.frames.forEach((e=>{e.debug_id&&(e.abs_path?t[e.abs_path]=e.debug_id:e.filename&&(t[e.filename]=e.debug_id),delete e.debug_id)}))}))}catch(e){}if(0===Object.keys(t).length)return;e.debug_meta=e.debug_meta||{},e.debug_meta.images=e.debug_meta.images||[];const n=e.debug_meta.images;Object.keys(t).forEach((e=>{n.push({type:"sourcemap",code_file:e,debug_id:t[e]})}))}(e),"number"==typeof h&&h>0?function(e,t,n){if(!e)return null;const i={...e,...e.breadcrumbs&&{breadcrumbs:e.breadcrumbs.map((e=>({...e,...e.data&&{data:(0,a.S8)(e.data,t,n)}})))},...e.user&&{user:(0,a.S8)(e.user,t,n)},...e.contexts&&{contexts:(0,a.S8)(e.contexts,t,n)},...e.extra&&{extra:(0,a.S8)(e.extra,t,n)}};return e.contexts&&e.contexts.trace&&i.contexts&&(i.contexts.trace=e.contexts.trace,e.contexts.trace.data&&(i.contexts.trace.data=(0,a.S8)(e.contexts.trace.data,t,n))),e.spans&&(i.spans=e.spans.map((e=>{const i=(0,u.et)(e).data;return i&&(e.data=(0,a.S8)(i,t,n)),e}))),i}(e,h,m):e)))}const I=new WeakMap;function p(e){if(e)return function(e){return e instanceof g.HG||"function"==typeof e}(e)||function(e){return Object.keys(e).some((e=>C.includes(e)))}(e)?{captureContext:e}:e}const C=["user","level","extra","contexts","tags","fingerprint","requestSession","propagationContext"]},3445:(e,t,n)=>{"use strict";n.d(t,{CC:()=>r,Qh:()=>l,aO:()=>a,cI:()=>g,et:()=>u,kX:()=>c,pK:()=>b});var i=n(4022),s=n(6524),o=n(9297);const r=0,a=1;function c(e){const{spanId:t,traceId:n}=e.spanContext(),{data:s,op:o,parent_span_id:r,status:a,tags:c,origin:l}=u(e);return(0,i.Ce)({data:s,op:o,parent_span_id:r,span_id:t,status:a,tags:c,trace_id:n,origin:l})}function l(e){const{traceId:t,spanId:n}=e.spanContext(),i=b(e);return(0,s.TC)(t,n,i)}function g(e){return"number"==typeof e?d(e):Array.isArray(e)?e[0]+e[1]/1e9:e instanceof Date?d(e.getTime()):(0,o.zf)()}function d(e){return e>9999999999?e/1e3:e}function u(e){return function(e){return"function"==typeof e.getSpanJSON}(e)?e.getSpanJSON():"function"==typeof e.toJSON?e.toJSON():{}}function b(e){const{traceFlags:t}=e.spanContext();return Boolean(t&a)}},7986:(e,t,n)=>{"use strict";n.d(t,{M:()=>i});const i="7.119.2"},2710:(e,t,n)=>{"use strict";n.r(t),n.d(t,{DEFAULT_USER_INCLUDES:()=>lt,Handlers:()=>s,Http:()=>oi,Hub:()=>ne.YZ,Integrations:()=>uo,NodeClient:()=>Pt,SDK_VERSION:()=>Zt.M,SEMANTIC_ATTRIBUTE_SENTRY_OP:()=>J,SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN:()=>z,SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE:()=>_,SEMANTIC_ATTRIBUTE_SENTRY_SOURCE:()=>k,Scope:()=>Gt.HG,Undici:()=>Ni,addBreadcrumb:()=>c.ZQ,addEventProcessor:()=>Ce,addGlobalEventProcessor:()=>Bt.lb,addIntegration:()=>l.Q8,addRequestDataToEvent:()=>ut,anrIntegration:()=>ji.a,autoDiscoverNodePerformanceMonitoringIntegrations:()=>Wt,captureCheckIn:()=>c.SE,captureConsoleIntegration:()=>fs,captureEvent:()=>c.r,captureException:()=>c.Cp,captureMessage:()=>c.wd,captureSession:()=>c.J5,close:()=>c.VN,configureScope:()=>c.PN,consoleIntegration:()=>Rn,contextLinesIntegration:()=>Qn,continueTrace:()=>ve,createGetModuleFromFilename:()=>Ji,createTransport:()=>we,cron:()=>bo,debugIntegration:()=>vs,dedupeIntegration:()=>Xs,deepReadDirSync:()=>Qi,defaultIntegrations:()=>zi,defaultStackParser:()=>Li,enableAnrDetection:()=>Oi,endSession:()=>c.ky,extraErrorDataIntegration:()=>Fs,extractRequestData:()=>dt,extractTraceparentData:()=>ke,flush:()=>c.bX,functionToStringIntegration:()=>b,getActiveSpan:()=>Ve,getActiveTransaction:()=>Fe,getClient:()=>c.KU,getCurrentHub:()=>ne.BF,getCurrentScope:()=>c.o5,getDefaultIntegrations:()=>Ui,getGlobalScope:()=>Gt.m6,getHubFromCarrier:()=>ne.Me,getIsolationScope:()=>ne.rm,getModuleFromFilename:()=>go,getSentryRelease:()=>Ei,getSpanStatusFromHttpCode:()=>Je,hapiErrorPlugin:()=>ss,hapiIntegration:()=>as,httpClientIntegration:()=>js,httpIntegration:()=>si,inboundFiltersIntegration:()=>B,init:()=>xi,isInitialized:()=>c.Dp,lastEventId:()=>c.Q,linkedErrorsIntegration:()=>w,localVariablesIntegration:()=>pi,makeMain:()=>ne.gM,makeNodeTransport:()=>In,metrics:()=>nt,modulesIntegration:()=>yi,nativeNodeFetchintegration:()=>Si,nodeContextIntegration:()=>Fn,onUncaughtExceptionIntegration:()=>Ai,onUnhandledRejectionIntegration:()=>Vi,parameterize:()=>it,reportingObserverIntegration:()=>no,requestDataIntegration:()=>Ct,rewriteFramesIntegration:()=>so,runWithAsyncContext:()=>ne.fx,sessionTimingIntegration:()=>ro,setContext:()=>c.o,setCurrentClient:()=>mt,setExtra:()=>c.l7,setExtras:()=>c.cx,setHttpStatus:()=>Ue,setMeasurement:()=>yt,setTag:()=>c.NA,setTags:()=>c.Wt,setUser:()=>c.gV,spanStatusfromHttpCode:()=>ze,spotlightIntegration:()=>Yi,startActiveSpan:()=>Ae,startInactiveSpan:()=>fe,startSession:()=>c.J0,startSpan:()=>Be,startSpanManual:()=>We,startTransaction:()=>c.nb,trace:()=>Ge,trpcMiddleware:()=>Pi,withActiveSpan:()=>c.hb,withIsolationScope:()=>c.rB,withMonitor:()=>c.T$,withScope:()=>c.v4});var i={};n.r(i),n.d(i,{FunctionToString:()=>I,InboundFilters:()=>A,LinkedErrors:()=>K});var s={};n.r(s),n.d(s,{errorHandler:()=>ts,extractRequestData:()=>Mi,parseRequest:()=>Di,requestHandler:()=>$i,tracingHandler:()=>qi,trpcMiddleware:()=>ns});var o={};n.r(o),n.d(o,{Anr:()=>ji.M,Console:()=>Yn,Context:()=>kn,ContextLines:()=>jn,Hapi:()=>cs,Http:()=>oi,LocalVariables:()=>Ii,Modules:()=>Zi,OnUncaughtException:()=>Wi,OnUnhandledRejection:()=>vi,RequestData:()=>ht,Spotlight:()=>Xi,Undici:()=>Ni});var r={};n.r(r),n.d(r,{Apollo:()=>us,Express:()=>Is,GraphQL:()=>hs,Mongo:()=>Zs,Mysql:()=>Gs,Postgres:()=>Bs,Prisma:()=>As});var a=n(4022),c=n(3741),l=n(5836);let g;const d="FunctionToString",u=new WeakMap,b=(0,l._C)((()=>({name:d,setupOnce(){g=Function.prototype.toString;try{Function.prototype.toString=function(...e){const t=(0,a.sp)(this),n=u.has((0,c.KU)())&&void 0!==t?t:this;return g.apply(n,e)}}catch(e){}},setup(e){u.set(e,!0)}}))),I=(0,l.F)(d,b);var p=n(7412),C=n(6936),h=n(9653),m=n(2220);const y=[/^Script error\.?$/,/^Javascript error: Script error\.? on line 0$/,/^ResizeObserver loop completed with undelivered notifications.$/,/^Cannot redefine property: googletag$/],Z=[/^.*\/healthcheck$/,/^.*\/healthy$/,/^.*\/live$/,/^.*\/ready$/,/^.*\/heartbeat$/,/^.*\/health$/,/^.*\/healthz$/],G="InboundFilters",B=(0,l._C)(((e={})=>({name:G,setupOnce(){},processEvent(t,n,i){const s=i.getOptions(),o=function(e={},t={}){return{allowUrls:[...e.allowUrls||[],...t.allowUrls||[]],denyUrls:[...e.denyUrls||[],...t.denyUrls||[]],ignoreErrors:[...e.ignoreErrors||[],...t.ignoreErrors||[],...e.disableErrorDefaults?[]:y],ignoreTransactions:[...e.ignoreTransactions||[],...t.ignoreTransactions||[],...e.disableTransactionDefaults?[]:Z],ignoreInternal:void 0===e.ignoreInternal||e.ignoreInternal}}(e,s);return function(e,t){return t.ignoreInternal&&function(e){try{return"SentryError"===e.exception.values[0].type}catch(e){}return!1}(e)?(m.T&&p.vF.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${(0,C.$X)(e)}`),!0):function(e,t){return!(e.type||!t||!t.length)&&function(e){const t=[];let n;e.message&&t.push(e.message);try{n=e.exception.values[e.exception.values.length-1]}catch(e){}return n&&n.value&&(t.push(n.value),n.type&&t.push(`${n.type}: ${n.value}`)),m.T&&0===t.length&&p.vF.error(`Could not extract message for event ${(0,C.$X)(e)}`),t}(e).some((e=>(0,h.Xr)(e,t)))}(e,t.ignoreErrors)?(m.T&&p.vF.warn(`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${(0,C.$X)(e)}`),!0):function(e,t){if("transaction"!==e.type||!t||!t.length)return!1;const n=e.transaction;return!!n&&(0,h.Xr)(n,t)}(e,t.ignoreTransactions)?(m.T&&p.vF.warn(`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${(0,C.$X)(e)}`),!0):function(e,t){if(!t||!t.length)return!1;const n=W(e);return!!n&&(0,h.Xr)(n,t)}(e,t.denyUrls)?(m.T&&p.vF.warn(`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${(0,C.$X)(e)}.\nUrl: ${W(e)}`),!0):!function(e,t){if(!t||!t.length)return!0;const n=W(e);return!n||(0,h.Xr)(n,t)}(e,t.allowUrls)&&(m.T&&p.vF.warn(`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${(0,C.$X)(e)}.\nUrl: ${W(e)}`),!0)}(t,o)?null:t}}))),A=(0,l.F)(G,B);function W(e){try{let t;try{t=e.exception.values[0].stacktrace.frames}catch(e){}return t?function(e=[]){for(let t=e.length-1;t>=0;t--){const n=e[t];if(n&&""!==n.filename&&"[native code]"!==n.filename)return n.filename||null}return null}(t):null}catch(t){return m.T&&p.vF.error(`Cannot extract url for event ${(0,C.$X)(e)}`),null}}var f=n(3816);function V(e,t,n=250,i,s,o,r){if(!(o.exception&&o.exception.values&&r&&(0,f.tH)(r.originalException,Error)))return;const a=o.exception.values.length>0?o.exception.values[o.exception.values.length-1]:void 0;var c,l;a&&(o.exception.values=(c=v(e,t,s,r.originalException,i,o.exception.values,a,0),l=n,c.map((e=>(e.value&&(e.value=(0,h.xv)(e.value,l)),e)))))}function v(e,t,n,i,s,o,r,a){if(o.length>=n+1)return o;let c=[...o];if((0,f.tH)(i[s],Error)){R(r,a);const o=e(t,i[s]),l=c.length;Y(o,s,l,a),c=v(e,t,n,i[s],s,[o,...c],o,l)}return Array.isArray(i.errors)&&i.errors.forEach(((i,o)=>{if((0,f.tH)(i,Error)){R(r,a);const l=e(t,i),g=c.length;Y(l,`errors[${o}]`,g,a),c=v(e,t,n,i,s,[l,...c],l,g)}})),c}function R(e,t){e.mechanism=e.mechanism||{type:"generic",handled:!0},e.mechanism={...e.mechanism,..."AggregateError"===e.type&&{is_exception_group:!0},exception_id:t}}function Y(e,t,n,i){e.mechanism=e.mechanism||{type:"generic",handled:!0},e.mechanism={...e.mechanism,type:"chained",source:t,exception_id:n,parent_id:i}}var X=n(2181);function H(e,t){return e(t.stack||"",1)}function S(e,t){const n={type:t.name||t.constructor.name,value:t.message},i=H(e,t);return i.length&&(n.stacktrace={frames:i}),n}const N="LinkedErrors",w=(0,l._C)(((e={})=>{const t=e.limit||5,n=e.key||"cause";return{name:N,setupOnce(){},preprocessEvent(e,i,s){const o=s.getOptions();V(S,o.stackParser,o.maxValueLength,n,t,e,i)}}})),K=(0,l.F)(N,w),F=i,k="sentry.source",_="sentry.sample_rate",J="sentry.op",z="sentry.origin";var U=n(5644);const x=/^(?:(\w+):)\/\/(?:(\w+)(?::(\w+)?)?@)([\w.-]+)(?::(\d+))?\/(.+)/;function T(e,t=!1){const{host:n,path:i,pass:s,port:o,projectId:r,protocol:a,publicKey:c}=e;return`${a}://${c}${t&&s?`:${s}`:""}@${n}${o?`:${o}`:""}/${i?`${i}/`:i}${r}`}function E(e){return{protocol:e.protocol,publicKey:e.publicKey||"",pass:e.pass||"",host:e.host,port:e.port||"",path:e.path||"",projectId:e.projectId}}var L=n(690);function Q(e,t=[]){return[e,t]}function j(e,t){const[n,i]=e;return[n,[...i,t]]}function O(e,t){const n=e[1];for(const e of n)if(t(e,e[0].type))return!0;return!1}function P(e,t){return(t||new TextEncoder).encode(e)}function M(e,t){const[n,i]=e;let s=JSON.stringify(n);function o(e){"string"==typeof s?s="string"==typeof e?s+e:[P(s,t),e]:s.push("string"==typeof e?P(e,t):e)}for(const e of i){const[t,n]=e;if(o(`\n${JSON.stringify(t)}\n`),"string"==typeof n||n instanceof Uint8Array)o(n);else{let e;try{e=JSON.stringify(n)}catch(t){e=JSON.stringify((0,X.S8)(n))}o(e)}}return"string"==typeof s?s:function(e){const t=e.reduce(((e,t)=>e+t.length),0),n=new Uint8Array(t);let i=0;for(const t of e)n.set(t,i),i+=t.length;return n}(s)}function D(e,t){const n="string"==typeof e.data?P(e.data,t):e.data;return[(0,a.Ce)({type:"attachment",length:n.length,filename:e.filename,content_type:e.contentType,attachment_type:e.attachmentType}),n]}const q={session:"session",sessions:"session",attachment:"attachment",transaction:"transaction",event:"error",client_report:"internal",user_report:"default",profile:"profile",replay_event:"replay",replay_recording:"replay",check_in:"monitor",feedback:"feedback",span:"span",statsd:"metric_bucket"};function $(e){return q[e]}function ee(e){if(!e||!e.sdk)return;const{name:t,version:n}=e.sdk;return{name:t,version:n}}class te extends Error{constructor(e,t="warn"){super(e),this.message=e,this.name=new.target.prototype.constructor.name,Object.setPrototypeOf(this,new.target.prototype),this.logLevel=t}}var ne=n(6641);function ie(e,t,n,i){return`${e}${t}${n}${Object.entries((0,a.Ce)(i)).sort(((e,t)=>e[0].localeCompare(t[0])))}`}function se(e){return e.replace(/[^\w]+/gi,"_")}function oe(e){return e.replace(/[^\w\-.]+/gi,"_")}function re(e){return e.replace(/[^\w\-./]+/gi,"")}const ae=[["\n","\\n"],["\r","\\r"],["\t","\\t"],["\\","\\\\"],["|","\\u{7c}"],[",","\\u{2c}"]];function ce(e){const t={};for(const i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[re(i)]=(n=String(e[i]),[...n].reduce(((e,t)=>e+function(e){for(const[t,n]of ae)if(e===t)return n;return e}(t)),"")));var n;return t}var le=n(7058),ge=n(5452),de=n(9475);const ue="Not capturing exception because it's already been captured.";class be{constructor(e){if(this._options=e,this._integrations={},this._integrationsInitialized=!1,this._numProcessing=0,this._outcomes={},this._hooks={},this._eventProcessors=[],e.dsn?this._dsn=function(e){const t="string"==typeof e?function(e){const t=x.exec(e);if(!t)return void(0,p.pq)((()=>{console.error(`Invalid Sentry Dsn: ${e}`)}));const[n,i,s="",o,r="",a]=t.slice(1);let c="",l=a;const g=l.split("/");if(g.length>1&&(c=g.slice(0,-1).join("/"),l=g.pop()),l){const e=l.match(/^\d+/);e&&(l=e[0])}return E({host:o,pass:s,path:c,projectId:l,port:r,protocol:n,publicKey:i})}(e):E(e);if(t&&function(e){if(!U.T)return!0;const{port:t,projectId:n,protocol:i}=e;return!(["protocol","publicKey","host","projectId"].find((t=>!e[t]&&(p.vF.error(`Invalid Sentry Dsn: ${t} missing`),!0)))||(n.match(/^\d+$/)?function(e){return"http"===e||"https"===e}(i)?t&&isNaN(parseInt(t,10))&&(p.vF.error(`Invalid Sentry Dsn: Invalid port ${t}`),1):(p.vF.error(`Invalid Sentry Dsn: Invalid protocol ${i}`),1):(p.vF.error(`Invalid Sentry Dsn: Invalid projectId ${n}`),1)))}(t))return t}(e.dsn):m.T&&p.vF.warn("No DSN provided, client will not send events."),this._dsn){const t=function(e,t={}){const n="string"==typeof t?t:t.tunnel,i="string"!=typeof t&&t._metadata?t._metadata.sdk:void 0;return n||`${function(e){return`${function(e){const t=e.protocol?`${e.protocol}:`:"",n=e.port?`:${e.port}`:"";return`${t}//${e.host}${n}${e.path?`/${e.path}`:""}/api/`}(e)}${e.projectId}/envelope/`}(e)}?${function(e,t){return(0,a.u4)({sentry_key:e.publicKey,sentry_version:"7",...t&&{sentry_client:`${t.name}/${t.version}`}})}(e,i)}`}(this._dsn,e);this._transport=e.transport({tunnel:this._options.tunnel,recordDroppedEvent:this.recordDroppedEvent.bind(this),...e.transportOptions,url:t})}}captureException(e,t,n){if((0,C.GR)(e))return void(m.T&&p.vF.log(ue));let i=t&&t.event_id;return this._process(this.eventFromException(e,t).then((e=>this._captureEvent(e,t,n))).then((e=>{i=e}))),i}captureMessage(e,t,n,i){let s=n&&n.event_id;const o=(0,f.NF)(e)?e:String(e),r=(0,f.sO)(e)?this.eventFromMessage(o,t,n):this.eventFromException(e,n);return this._process(r.then((e=>this._captureEvent(e,n,i))).then((e=>{s=e}))),s}captureEvent(e,t,n){if(t&&t.originalException&&(0,C.GR)(t.originalException))return void(m.T&&p.vF.log(ue));let i=t&&t.event_id;const s=(e.sdkProcessingMetadata||{}).capturedSpanScope;return this._process(this._captureEvent(e,t,s||n).then((e=>{i=e}))),i}captureSession(e){"string"!=typeof e.release?m.T&&p.vF.warn("Discarded session because of missing or non-string release"):(this.sendSession(e),(0,le.qO)(e,{init:!1}))}getDsn(){return this._dsn}getOptions(){return this._options}getSdkMetadata(){return this._options._metadata}getTransport(){return this._transport}flush(e){const t=this._transport;return t?(this.metricsAggregator&&this.metricsAggregator.flush(),this._isClientDoneProcessing(e).then((n=>t.flush(e).then((e=>n&&e))))):(0,L.XW)(!0)}close(e){return this.flush(e).then((e=>(this.getOptions().enabled=!1,this.metricsAggregator&&this.metricsAggregator.close(),e)))}getEventProcessors(){return this._eventProcessors}addEventProcessor(e){this._eventProcessors.push(e)}setupIntegrations(e){(e&&!this._integrationsInitialized||this._isEnabled()&&!this._integrationsInitialized)&&this._setupIntegrations()}init(){this._isEnabled()&&this._setupIntegrations()}getIntegrationById(e){return this.getIntegrationByName(e)}getIntegrationByName(e){return this._integrations[e]}getIntegration(e){try{return this._integrations[e.id]||null}catch(t){return m.T&&p.vF.warn(`Cannot retrieve integration ${e.id} from the current Client`),null}}addIntegration(e){const t=this._integrations[e.name];(0,l.qm)(this,e,this._integrations),t||(0,l.lc)(this,[e])}sendEvent(e,t={}){this.emit("beforeSendEvent",e,t);let n=function(e,t,n,i){const s=ee(n),o=e.type&&"replay_event"!==e.type?e.type:"event";!function(e,t){t&&(e.sdk=e.sdk||{},e.sdk.name=e.sdk.name||t.name,e.sdk.version=e.sdk.version||t.version,e.sdk.integrations=[...e.sdk.integrations||[],...t.integrations||[]],e.sdk.packages=[...e.sdk.packages||[],...t.packages||[]])}(e,n&&n.sdk);const r=function(e,t,n,i){const s=e.sdkProcessingMetadata&&e.sdkProcessingMetadata.dynamicSamplingContext;return{event_id:e.event_id,sent_at:(new Date).toISOString(),...t&&{sdk:t},...!!n&&i&&{dsn:T(i)},...s&&{trace:(0,a.Ce)({...s})}}}(e,s,i,t);return delete e.sdkProcessingMetadata,Q(r,[[{type:o},e]])}(e,this._dsn,this._options._metadata,this._options.tunnel);for(const e of t.attachments||[])n=j(n,D(e,this._options.transportOptions&&this._options.transportOptions.textEncoder));const i=this._sendEnvelope(n);i&&i.then((t=>this.emit("afterSendEvent",e,t)),null)}sendSession(e){const t=function(e,t,n,i){const s=ee(n);return Q({sent_at:(new Date).toISOString(),...s&&{sdk:s},...!!i&&t&&{dsn:T(t)}},["aggregates"in e?[{type:"sessions"},e]:[{type:"session"},e.toJSON()]])}(e,this._dsn,this._options._metadata,this._options.tunnel);this._sendEnvelope(t)}recordDroppedEvent(e,t,n){if(this._options.sendClientReports){const i="number"==typeof n?n:1,s=`${e}:${t}`;m.T&&p.vF.log(`Recording outcome: "${s}"${i>1?` (${i} times)`:""}`),this._outcomes[s]=(this._outcomes[s]||0)+i}}captureAggregateMetrics(e){m.T&&p.vF.log(`Flushing aggregated metrics, number of metrics: ${e.length}`);const t=function(e,t,n,i){const s={sent_at:(new Date).toISOString()};n&&n.sdk&&(s.sdk={name:n.sdk.name,version:n.sdk.version}),i&&t&&(s.dsn=T(t));const o=function(e){const t=function(e){let t="";for(const n of e){const e=Object.entries(n.tags),i=e.length>0?`|#${e.map((([e,t])=>`${e}:${t}`)).join(",")}`:"";t+=`${n.name}@${n.unit}:${n.metric}|${n.metricType}${i}|T${n.timestamp}\n`}return t}(e);return[{type:"statsd",length:t.length},t]}(e);return Q(s,[o])}(e,this._dsn,this._options._metadata,this._options.tunnel);this._sendEnvelope(t)}on(e,t){this._hooks[e]||(this._hooks[e]=[]),this._hooks[e].push(t)}emit(e,...t){this._hooks[e]&&this._hooks[e].forEach((e=>e(...t)))}_setupIntegrations(){const{integrations:e}=this._options;this._integrations=(0,l.P$)(this,e),(0,l.lc)(this,e),this._integrationsInitialized=!0}_updateSessionFromEvent(e,t){let n=!1,i=!1;const s=t.exception&&t.exception.values;if(s){i=!0;for(const e of s){const t=e.mechanism;if(t&&!1===t.handled){n=!0;break}}}const o="ok"===e.status;(o&&0===e.errors||o&&n)&&((0,le.qO)(e,{...n&&{status:"crashed"},errors:e.errors||Number(i||n)}),this.captureSession(e))}_isClientDoneProcessing(e){return new L.T2((t=>{let n=0;const i=setInterval((()=>{0==this._numProcessing?(clearInterval(i),t(!0)):(n+=1,e&&n>=e&&(clearInterval(i),t(!1)))}),1)}))}_isEnabled(){return!1!==this.getOptions().enabled&&void 0!==this._transport}_prepareEvent(e,t,n,i=(0,ne.rm)()){const s=this.getOptions(),o=Object.keys(this._integrations);return!t.integrations&&o.length>0&&(t.integrations=o),this.emit("preprocessEvent",e,t),(0,de.mG)(s,e,t,n,this,i).then((e=>{if(null===e)return e;const t={...i.getPropagationContext(),...n?n.getPropagationContext():void 0};if((!e.contexts||!e.contexts.trace)&&t){const{traceId:i,spanId:s,parentSpanId:o,dsc:r}=t;e.contexts={trace:{trace_id:i,span_id:s,parent_span_id:o},...e.contexts};const a=r||(0,ge.l)(i,this,n);e.sdkProcessingMetadata={dynamicSamplingContext:a,...e.sdkProcessingMetadata}}return e}))}_captureEvent(e,t={},n){return this._processEvent(e,t,n).then((e=>e.event_id),(e=>{if(m.T){const t=e;"log"===t.logLevel?p.vF.log(t.message):p.vF.warn(t)}}))}_processEvent(e,t,n){const i=this.getOptions(),{sampleRate:s}=i,o=pe(e),r=Ie(e),a=e.type||"error",c=`before send for type \`${a}\``;if(r&&"number"==typeof s&&Math.random()>s)return this.recordDroppedEvent("sample_rate","error",e),(0,L.xg)(new te(`Discarding event because it's not included in the random sample (sampling rate = ${s})`,"log"));const l="replay_event"===a?"replay":a,g=(e.sdkProcessingMetadata||{}).capturedSpanIsolationScope;return this._prepareEvent(e,t,n,g).then((n=>{if(null===n)throw this.recordDroppedEvent("event_processor",l,e),new te("An event processor returned `null`, will not send event.","log");if(t.data&&!0===t.data.__sentry__)return n;const s=function(e,t,n){const{beforeSend:i,beforeSendTransaction:s}=e;if(Ie(t)&&i)return i(t,n);if(pe(t)&&s){if(t.spans){const e=t.spans.length;t.sdkProcessingMetadata={...t.sdkProcessingMetadata,spanCountBeforeProcessing:e}}return s(t,n)}return t}(i,n,t);return function(e,t){const n=`${t} must return \`null\` or a valid event.`;if((0,f.Qg)(e))return e.then((e=>{if(!(0,f.Qd)(e)&&null!==e)throw new te(n);return e}),(e=>{throw new te(`${t} rejected with ${e}`)}));if(!(0,f.Qd)(e)&&null!==e)throw new te(n);return e}(s,c)})).then((i=>{if(null===i){if(this.recordDroppedEvent("before_send",l,e),o){const t=1+(e.spans||[]).length;this.recordDroppedEvent("before_send","span",t)}throw new te(`${c} returned \`null\`, will not send event.`,"log")}const s=n&&n.getSession();if(!o&&s&&this._updateSessionFromEvent(s,i),o){const e=(i.sdkProcessingMetadata&&i.sdkProcessingMetadata.spanCountBeforeProcessing||0)-(i.spans?i.spans.length:0);e>0&&this.recordDroppedEvent("before_send","span",e)}const r=i.transaction_info;if(o&&r&&i.transaction!==e.transaction){const e="custom";i.transaction_info={...r,source:e}}return this.sendEvent(i,t),i})).then(null,(e=>{if(e instanceof te)throw e;throw this.captureException(e,{data:{__sentry__:!0},originalException:e}),new te(`Event processing pipeline threw an error, original event will not be sent. Details have been sent as a new event.\nReason: ${e}`)}))}_process(e){this._numProcessing++,e.then((e=>(this._numProcessing--,e)),(e=>(this._numProcessing--,e)))}_sendEnvelope(e){if(this.emit("beforeEnvelope",e),this._isEnabled()&&this._transport)return this._transport.send(e).then(null,(e=>{m.T&&p.vF.error("Error while sending event:",e)}));m.T&&p.vF.error("Transport disabled")}_clearOutcomes(){const e=this._outcomes;return this._outcomes={},Object.keys(e).map((t=>{const[n,i]=t.split(":");return{reason:n,category:i,quantity:e[t]}}))}}function Ie(e){return void 0===e.type}function pe(e){return"transaction"===e.type}function Ce(e){const t=(0,c.KU)();t&&t.addEventProcessor&&t.addEventProcessor(e)}var he=n(6524),me=n(3445);function ye(e,t,n=()=>{}){let i;try{i=e()}catch(e){throw t(e),n(),e}return function(e,t,n){return(0,f.Qg)(e)?e.then((e=>(n(),e)),(e=>{throw t(e),n(),e})):(n(),e)}(i,t,n)}function Ze(e){if("boolean"==typeof __SENTRY_TRACING__&&!__SENTRY_TRACING__)return!1;const t=(0,c.KU)(),n=e||t&&t.getOptions();return!!n&&(n.enableTracing||"tracesSampleRate"in n||"tracesSampler"in n)}function Ge(e,t,n=()=>{},i=()=>{}){const s=(0,ne.BF)(),o=(0,c.o5)(),r=o.getSpan(),a=Ye(e),l=Re(s,{parentSpan:r,spanContext:a,forceTransaction:!1,scope:o});return o.setSpan(l),ye((()=>t(l)),(e=>{l&&l.setStatus("internal_error"),n(e,l)}),(()=>{l&&l.end(),o.setSpan(r),i()}))}function Be(e,t){const n=Ye(e);return(0,ne.fx)((()=>(0,c.v4)(e.scope,(i=>{const s=(0,ne.BF)(),o=i.getSpan(),r=e.onlyIfParent&&!o?void 0:Re(s,{parentSpan:o,spanContext:n,forceTransaction:e.forceTransaction,scope:i});return ye((()=>t(r)),(()=>{if(r){const{status:e}=(0,me.et)(r);e&&"ok"!==e||r.setStatus("internal_error")}}),(()=>r&&r.end()))}))))}const Ae=Be;function We(e,t){const n=Ye(e);return(0,ne.fx)((()=>(0,c.v4)(e.scope,(i=>{const s=(0,ne.BF)(),o=i.getSpan(),r=e.onlyIfParent&&!o?void 0:Re(s,{parentSpan:o,spanContext:n,forceTransaction:e.forceTransaction,scope:i});function a(){r&&r.end()}return ye((()=>t(r,a)),(()=>{if(r&&r.isRecording()){const{status:e}=(0,me.et)(r);e&&"ok"!==e||r.setStatus("internal_error")}}))}))))}function fe(e){if(!Ze())return;const t=Ye(e),n=(0,ne.BF)(),i=e.scope?e.scope.getSpan():Ve();if(e.onlyIfParent&&!i)return;const s=(e.scope||(0,c.o5)()).clone();return Re(n,{parentSpan:i,spanContext:t,forceTransaction:e.forceTransaction,scope:s})}function Ve(){return(0,c.o5)().getSpan()}const ve=({sentryTrace:e,baggage:t},n)=>{const i=(0,c.o5)(),{traceparentData:s,dynamicSamplingContext:o,propagationContext:r}=(0,he.E0)(e,t);i.setPropagationContext(r),m.T&&s&&p.vF.log(`[Tracing] Continuing trace ${s.traceId}.`);const l={...s,metadata:(0,a.Ce)({dynamicSamplingContext:o})};return n?(0,ne.fx)((()=>n(l))):l};function Re(e,{parentSpan:t,spanContext:n,forceTransaction:i,scope:s}){if(!Ze())return;const o=(0,ne.rm)();let r;if(t&&!i)r=t.startChild(n);else if(t){const i=(0,ge.k)(t),{traceId:s,spanId:o}=t.spanContext(),a=(0,me.pK)(t);r=e.startTransaction({traceId:s,parentSpanId:o,parentSampled:a,...n,metadata:{dynamicSamplingContext:i,...n.metadata}})}else{const{traceId:t,dsc:i,parentSpanId:a,sampled:c}={...o.getPropagationContext(),...s.getPropagationContext()};r=e.startTransaction({traceId:t,parentSpanId:a,parentSampled:c,...n,metadata:{dynamicSamplingContext:i,...n.metadata}})}return s.setSpan(r),function(e,t,n){e&&((0,a.my)(e,He,n),(0,a.my)(e,Xe,t))}(r,s,o),r}function Ye(e){if(e.startTime){const t={...e};return t.startTimestamp=(0,me.cI)(e.startTime),delete t.startTime,t}return e}const Xe="_sentryScope",He="_sentryIsolationScope";const Se=6e4;const Ne=30;function we(e,t,n=function(e){const t=[];function n(e){return t.splice(t.indexOf(e),1)[0]}return{$:t,add:function(i){if(!(void 0===e||t.lengthn(s))).then(null,(()=>n(s).then(null,(()=>{})))),s},drain:function(e){return new L.T2(((n,i)=>{let s=t.length;if(!s)return n(!0);const o=setTimeout((()=>{e&&e>0&&n(!1)}),e);t.forEach((e=>{(0,L.XW)(e).then((()=>{--s||(clearTimeout(o),n(!0))}),i)}))}))}}}(e.bufferSize||Ne)){let i={};function s(s){const o=[];if(O(s,((t,n)=>{const s=$(n);if(function(e,t,n=Date.now()){return function(e,t){return e[t]||e.all||0}(e,t)>n}(i,s)){const i=Ke(t,n);e.recordDroppedEvent("ratelimit_backoff",s,i)}else o.push(t)})),0===o.length)return(0,L.XW)();const r=Q(s[0],o),a=t=>{O(r,((n,i)=>{const s=Ke(n,i);e.recordDroppedEvent(t,$(i),s)}))};return n.add((()=>t({body:M(r,e.textEncoder)}).then((e=>(void 0!==e.statusCode&&(e.statusCode<200||e.statusCode>=300)&&m.T&&p.vF.warn(`Sentry responded with status code ${e.statusCode} to sent event.`),i=function(e,{statusCode:t,headers:n},i=Date.now()){const s={...e},o=n&&n["x-sentry-rate-limits"],r=n&&n["retry-after"];if(o)for(const e of o.trim().split(",")){const[t,n,,,o]=e.split(":",5),r=parseInt(t,10),a=1e3*(isNaN(r)?60:r);if(n)for(const e of n.split(";"))"metric_bucket"===e&&o&&!o.split(";").includes("custom")||(s[e]=i+a);else s.all=i+a}else r?s.all=i+function(e,t=Date.now()){const n=parseInt(`${e}`,10);if(!isNaN(n))return 1e3*n;const i=Date.parse(`${e}`);return isNaN(i)?Se:i-t}(r,i):429===t&&(s.all=i+6e4);return s}(i,e),e)),(e=>{throw a("network_error"),e})))).then((e=>e),(e=>{if(e instanceof te)return m.T&&p.vF.error("Skipped sending event because buffer is full."),a("queue_overflow"),(0,L.XW)();throw e}))}return s.__sentry__baseTransport__=!0,{send:s,flush:e=>n.drain(e)}}function Ke(e,t){if("event"===t||"transaction"===t)return Array.isArray(e)?e[1]:void 0}function Fe(e){return(e||(0,ne.BF)()).getScope().getTransaction()}const ke=he.nc;var _e;function Je(e){if(e<400&&e>=100)return"ok";if(e>=400&&e<500)switch(e){case 401:return"unauthenticated";case 403:return"permission_denied";case 404:return"not_found";case 409:return"already_exists";case 413:return"failed_precondition";case 429:return"resource_exhausted";default:return"invalid_argument"}if(e>=500&&e<600)switch(e){case 501:return"unimplemented";case 503:return"unavailable";case 504:return"deadline_exceeded";default:return"internal_error"}return"unknown_error"}!function(e){e.Ok="ok",e.DeadlineExceeded="deadline_exceeded",e.Unauthenticated="unauthenticated",e.PermissionDenied="permission_denied",e.NotFound="not_found",e.ResourceExhausted="resource_exhausted",e.InvalidArgument="invalid_argument",e.Unimplemented="unimplemented",e.Unavailable="unavailable",e.InternalError="internal_error",e.UnknownError="unknown_error",e.Cancelled="cancelled",e.AlreadyExists="already_exists",e.FailedPrecondition="failed_precondition",e.Aborted="aborted",e.OutOfRange="out_of_range",e.DataLoss="data_loss"}(_e||(_e={}));const ze=Je;function Ue(e,t){e.setTag("http.status_code",String(t)),e.setData("http.response.status_code",t);const n=Je(t);"unknown_error"!==n&&e.setStatus(n)}const xe="c",Te="g",Ee="s",Le="d";var Qe=n(9297);const je={[xe]:class{constructor(e){this._value=e}get weight(){return 1}add(e){this._value+=e}toString(){return`${this._value}`}},[Te]:class{constructor(e){this._last=e,this._min=e,this._max=e,this._sum=e,this._count=1}get weight(){return 5}add(e){this._last=e,ethis._max&&(this._max=e),this._sum+=e,this._count++}toString(){return`${this._last}:${this._min}:${this._max}:${this._sum}:${this._count}`}},[Le]:class{constructor(e){this._value=[e]}get weight(){return this._value.length}add(e){this._value.push(e)}toString(){return this._value.join(":")}},[Ee]:class{constructor(e){this.first=e,this._value=new Set([e])}get weight(){return this._value.size}add(e){this._value.add(e)}toString(){return Array.from(this._value).map((e=>"string"==typeof e?function(e){let t=0;for(let n=0;n>>0}(e):e)).join(":")}}};let Oe;function Pe(e){return Oe?Oe.get(e):void 0}function Me(e){const t=Pe(e);if(!t)return;const n={};for(const[,[e,i]]of t)n[e]||(n[e]=[]),n[e].push((0,a.Ce)(i));return n}function De(e,t,n,i,s,o){const r=Ve();if(r){const a=Pe(r)||new Map,c=`${e}:${t}@${i}`,l=a.get(o);if(l){const[,e]=l;a.set(o,[c,{min:Math.min(e.min,n),max:Math.max(e.max,n),count:e.count+=1,sum:e.sum+=n,tags:e.tags}])}else a.set(o,[c,{min:n,max:n,count:1,sum:n,tags:s}]);Oe||(Oe=new WeakMap),Oe.set(r,a)}}class qe{constructor(e){this._client=e,this._buckets=new Map,this._interval=setInterval((()=>this.flush()),5e3)}add(e,t,n,i="none",s={},o=(0,Qe.zf)()){const r=Math.floor(o),a=oe(t),c=ce(s),l=se(i),g=ie(e,a,l,c);let d=this._buckets.get(g);const u=d&&e===Ee?d.metric.weight:0;d?(d.metric.add(n),d.timestampe));this._client.captureAggregateMetrics(e)}this._buckets.clear()}}close(){clearInterval(this._interval),this.flush()}}const $e="MetricsAggregator",et=(0,l._C)((()=>({name:$e,setupOnce(){},setup(e){e.metricsAggregator=new qe(e)}})));function tt(e,t,n,i={}){const s=(0,c.KU)(),o=(0,c.o5)();if(s){if(!s.metricsAggregator)return void(m.T&&p.vF.warn("No metrics aggregator enabled. Please add the MetricsAggregator integration to use metrics APIs"));const{unit:r,tags:a,timestamp:c}=i,{release:l,environment:g}=s.getOptions(),d=o.getTransaction(),u={};l&&(u.release=l),g&&(u.environment=g),d&&(u.transaction=(0,me.et)(d).description||""),m.T&&p.vF.log(`Adding value of ${n} to ${e} metric ${t}`),s.metricsAggregator.add(e,t,n,r,{...u,...a},c)}}const nt={increment:function(e,t=1,n){tt("c",e,t,n)},distribution:function(e,t,n){tt("d",e,t,n)},set:function(e,t,n){tt(Ee,e,t,n)},gauge:function(e,t,n){tt("g",e,t,n)},MetricsAggregator:(0,l.F)($e,et),metricsAggregatorIntegration:et};function it(e,...t){const n=new String(String.raw(e,...t));return n.__sentry_template_string__=e.join("\0").replace(/%/g,"%%").replace(/\0/g,"%s"),n.__sentry_template_values__=t,n}function st(e){return e.split(/[\?#]/,1)[0]}function ot(e){return e.split(/\\?\//).filter((e=>e.length>0&&","!==e)).length}function rt(e){const{protocol:t,host:n,path:i}=e;return`${t?`${t}://`:""}${n&&n.replace(/^.*@/,"[filtered]:[filtered]@").replace(/(:80)$/,"").replace(/(:443)$/,"")||""}${i}`}const at={ip:!1,request:!0,transaction:!0,user:!0},ct=["cookies","data","headers","method","query_string","url"],lt=["id","username","email"];function gt(e,t={}){const n=e.method&&e.method.toUpperCase();let i="",s="url";t.customRoute||e.route?(i=t.customRoute||`${e.baseUrl||""}${e.route&&e.route.path}`,s="route"):(e.originalUrl||e.url)&&(i=st(e.originalUrl||e.url||""));let o="";return t.method&&n&&(o+=n),t.method&&t.path&&(o+=" "),t.path&&i&&(o+=i),[o,s]}function dt(e,t){const{include:n=ct,deps:i}=t||{},s={},o=e.headers||{},r=e.method,a=o.host||e.hostname||e.host||"",c="https"===e.protocol||e.socket&&e.socket.encrypted?"https":"http",l=e.originalUrl||e.url||"",g=l.startsWith(c)?l:`${c}://${a}${l}`;return n.forEach((t=>{switch(t){case"headers":s.headers=o,n.includes("cookies")||delete s.headers.cookie;break;case"method":s.method=r;break;case"url":s.url=g;break;case"cookies":s.cookies=e.cookies||o.cookie&&function(e){const t={};let n=0;for(;n{e&&t in e&&(n[t]=e[t])})),n}(t.user,i.user):{};Object.keys(n).length&&(e.user={...e.user,...n})}if(i.ip){const n=t.ip||t.socket&&t.socket.remoteAddress;n&&(e.user={...e.user,ip_address:n})}return i.transaction&&!e.transaction&&(e.transaction=function(e,t){switch(t){case"path":return gt(e,{path:!0})[0];case"handler":return e.route&&e.route.stack&&e.route.stack[0]&&e.route.stack[0].name||"";default:return gt(e,{path:!0,method:!0,customRoute:e._reconstructedRoute?e._reconstructedRoute:void 0})[0]}}(t,i.transaction)),e}function bt(e,t){let n=e.originalUrl||e.url||"";if(n){n.startsWith("/")&&(n=`http://dogs.are.great${n}`);try{return e.query||"undefined"!=typeof URL&&new URL(n).search.slice(1)||t&&t.url&&t.url.parse(n).query||void 0}catch(e){return}}}const It={include:{cookies:!0,data:!0,headers:!0,ip:!1,query_string:!0,url:!0,user:{id:!0,username:!0,email:!0}},transactionNamingScheme:"methodPath"},pt="RequestData",Ct=(0,l._C)(((e={})=>{const t=ut,n={...It,...e,include:{method:!0,...It.include,...e.include,user:e.include&&"boolean"==typeof e.include.user?e.include.user:{...It.include.user,...(e.include||{}).user}}};return{name:pt,setupOnce(){},processEvent(e,i,s){const{transactionNamingScheme:o}=n,{sdkProcessingMetadata:r={}}=e,a=r.request;if(!a)return e;const c=r.requestDataOptionsFromExpressHandler||r.requestDataOptionsFromGCPWrapper||function(e){const{transactionNamingScheme:t,include:{ip:n,user:i,...s}}=e,o=[];for(const[e,t]of Object.entries(s))t&&o.push(e);let r;if(void 0===i)r=!0;else if("boolean"==typeof i)r=i;else{const e=[];for(const[t,n]of Object.entries(i))n&&e.push(t);r=e}return{include:{ip:n,user:r,request:0!==o.length?o:void 0,transaction:t}}}(n),l=t(e,a,c);if("transaction"===e.type||"handler"===o)return l;const g=a._sentryTransaction;if(g){const e=(0,me.et)(g).description||"",t="sentry.javascript.nextjs"===function(e){try{return e.getOptions()._metadata.sdk.name}catch(e){return}}(s)?e.startsWith("/api"):"path"!==o,[n]=gt(a,{path:!0,method:t,customRoute:e});l.transaction=n}return l}}})),ht=(0,l.F)(pt,Ct);function mt(e){const t=(0,ne.BF)().getStackTop();t.client=e,t.scope.setClient(e)}function yt(e,t,n){const i=Fe();i&&i.setMeasurement(e,t,n)}var Zt=n(7986),Gt=n(2486),Bt=n(2531),At=n(2786);function Wt(){const e=At.j.map((e=>{try{return e()}catch(e){return}})).filter((e=>!!e));return 0===e.length&&p.vF.warn("Performance monitoring integrations could not be automatically loaded."),e.filter((e=>!!e.loadDependency()))}const ft=require("os"),Vt=require("util");class vt{constructor(e){this._client=e,this._buckets=new Map,this._bucketsTotalWeight=0,this._interval=setInterval((()=>this._flush()),1e4),this._interval.unref&&this._interval.unref(),this._flushShift=Math.floor(1e4*Math.random()/1e3),this._forceFlush=!1}add(e,t,n,i="none",s={},o=(0,Qe.zf)()){const r=Math.floor(o),a=oe(t),c=ce(s),l=se(i),g=ie(e,a,l,c);let d=this._buckets.get(g);const u=d&&e===Ee?d.metric.weight:0;d?(d.metric.add(n),d.timestamp=1e4&&this.flush()}flush(){this._forceFlush=!0,this._flush()}close(){this._forceFlush=!0,clearInterval(this._interval),this._flush()}_flush(){if(this._forceFlush)return this._forceFlush=!1,this._bucketsTotalWeight=0,this._captureMetrics(this._buckets),void this._buckets.clear();const e=Math.floor((0,Qe.zf)())-10-this._flushShift,t=new Map;for(const[n,i]of this._buckets)i.timestamp<=e&&(t.set(n,i),this._bucketsTotalWeight-=i.metric.weight);for(const[e]of t)this._buckets.delete(e);this._captureMetrics(t)}_captureMetrics(e){if(e.size>0&&this._client.captureAggregateMetrics){const t=Array.from(e).map((([,e])=>e));this._client.captureAggregateMetrics(t)}}}class Rt{constructor(e,t){this._client=e,this.flushTimeout=60,this._pendingAggregates={},this._isEnabled=!0,this._intervalId=setInterval((()=>this.flush()),1e3*this.flushTimeout),this._intervalId.unref&&this._intervalId.unref(),this._sessionAttrs=t}flush(){const e=this.getSessionAggregates();0!==e.aggregates.length&&(this._pendingAggregates={},this._client.sendSession(e))}getSessionAggregates(){const e=Object.keys(this._pendingAggregates).map((e=>this._pendingAggregates[parseInt(e)])),t={attrs:this._sessionAttrs,aggregates:e};return(0,a.Ce)(t)}close(){clearInterval(this._intervalId),this._isEnabled=!1,this.flush()}incrementSessionStatusCount(){if(!this._isEnabled)return;const e=(0,c.o5)(),t=e.getRequestSession();t&&t.status&&(this._incrementSessionStatusCount(t.status,new Date),e.setRequestSession(void 0))}_incrementSessionStatusCount(e,t){const n=new Date(t).setSeconds(0,0);this._pendingAggregates[n]=this._pendingAggregates[n]||{};const i=this._pendingAggregates[n];switch(i.started||(i.started=new Date(n).toISOString()),e){case"errored":return i.errored=(i.errored||0)+1,i.errored;case"ok":return i.exited=(i.exited||0)+1,i.exited;default:return i.crashed=(i.crashed||0)+1,i.crashed}}}var Yt=n(6341),Xt=n(7930);const Ht={},St={};function Nt(e,t){Ht[e]=Ht[e]||[],Ht[e].push(t)}function wt(e,t){St[e]||(t(),St[e]=!0)}function Kt(e,t){const n=e&&Ht[e];if(n)for(const i of n)try{i(t)}catch(t){U.T&&p.vF.error(`Error while triggering instrumentation handler.\nType: ${e}\nName: ${(0,Xt.qQ)(i)}\nError:`,t)}}let Ft=null;function kt(){Ft=Yt.OW.onerror,Yt.OW.onerror=function(e,t,n,i,s){return Kt("error",{column:i,error:s,line:n,msg:e,url:t}),!(!Ft||Ft.__SENTRY_LOADER__)&&Ft.apply(this,arguments)},Yt.OW.onerror.__SENTRY_INSTRUMENTED__=!0}let _t=null;function Jt(){_t=Yt.OW.onunhandledrejection,Yt.OW.onunhandledrejection=function(e){return Kt("unhandledrejection",e),!(_t&&!_t.__SENTRY_LOADER__)||_t.apply(this,arguments)},Yt.OW.onunhandledrejection.__SENTRY_INSTRUMENTED__=!0}let zt=!1;function Ut(){const e=Fe();if(e){const t="internal_error";m.T&&p.vF.log(`[Tracing] Transaction: ${t} -> Global error occured`),e.setStatus(t)}}Ut.tag="sentry_tracingErrorCallback";var xt=n(4636);class Tt{constructor(e=1e3){this._maxlen=e,this.spans=[]}add(e){this.spans.length>this._maxlen?e.spanRecorder=void 0:this.spans.push(e)}}class Et{constructor(e={}){this._traceId=e.traceId||(0,C.eJ)(),this._spanId=e.spanId||(0,C.eJ)().substring(16),this._startTime=e.startTimestamp||(0,Qe.zf)(),this.tags=e.tags?{...e.tags}:{},this.data=e.data?{...e.data}:{},this.instrumenter=e.instrumenter||"sentry",this._attributes={},this.setAttributes({[z]:e.origin||"manual",[J]:e.op,...e.attributes}),this._name=e.name||e.description,e.parentSpanId&&(this._parentSpanId=e.parentSpanId),"sampled"in e&&(this._sampled=e.sampled),e.status&&(this._status=e.status),e.endTimestamp&&(this._endTime=e.endTimestamp),void 0!==e.exclusiveTime&&(this._exclusiveTime=e.exclusiveTime),this._measurements=e.measurements?{...e.measurements}:{}}get name(){return this._name||""}set name(e){this.updateName(e)}get description(){return this._name}set description(e){this._name=e}get traceId(){return this._traceId}set traceId(e){this._traceId=e}get spanId(){return this._spanId}set spanId(e){this._spanId=e}set parentSpanId(e){this._parentSpanId=e}get parentSpanId(){return this._parentSpanId}get sampled(){return this._sampled}set sampled(e){this._sampled=e}get attributes(){return this._attributes}set attributes(e){this._attributes=e}get startTimestamp(){return this._startTime}set startTimestamp(e){this._startTime=e}get endTimestamp(){return this._endTime}set endTimestamp(e){this._endTime=e}get status(){return this._status}set status(e){this._status=e}get op(){return this._attributes[J]}set op(e){this.setAttribute(J,e)}get origin(){return this._attributes[z]}set origin(e){this.setAttribute(z,e)}spanContext(){const{_spanId:e,_traceId:t,_sampled:n}=this;return{spanId:e,traceId:t,traceFlags:n?me.aO:me.CC}}startChild(e){const t=new Et({...e,parentSpanId:this._spanId,sampled:this._sampled,traceId:this._traceId});t.spanRecorder=this.spanRecorder,t.spanRecorder&&t.spanRecorder.add(t);const n=(0,xt.z)(this);if(t.transaction=n,m.T&&n){const i=`[Tracing] Starting '${e&&e.op||"< unknown op >"}' span on transaction '${(0,me.et)(t).description||"< unknown name >"}' (${n.spanContext().spanId}).`;p.vF.log(i),this._logMessage=i}return t}setTag(e,t){return this.tags={...this.tags,[e]:t},this}setData(e,t){return this.data={...this.data,[e]:t},this}setAttribute(e,t){void 0===t?delete this._attributes[e]:this._attributes[e]=t}setAttributes(e){Object.keys(e).forEach((t=>this.setAttribute(t,e[t])))}setStatus(e){return this._status=e,this}setHttpStatus(e){return Ue(this,e),this}setName(e){this.updateName(e)}updateName(e){return this._name=e,this}isSuccess(){return"ok"===this._status}finish(e){return this.end(e)}end(e){if(this._endTime)return;const t=(0,xt.z)(this);if(m.T&&t&&t.spanContext().spanId!==this._spanId){const e=this._logMessage;e&&p.vF.log(e.replace("Starting","Finishing"))}this._endTime=(0,me.cI)(e)}toTraceparent(){return(0,me.Qh)(this)}toContext(){return(0,a.Ce)({data:this._getData(),description:this._name,endTimestamp:this._endTime,op:this.op,parentSpanId:this._parentSpanId,sampled:this._sampled,spanId:this._spanId,startTimestamp:this._startTime,status:this._status,tags:this.tags,traceId:this._traceId})}updateWithContext(e){return this.data=e.data||{},this._name=e.name||e.description,this._endTime=e.endTimestamp,this.op=e.op,this._parentSpanId=e.parentSpanId,this._sampled=e.sampled,this._spanId=e.spanId||this._spanId,this._startTime=e.startTimestamp||this._startTime,this._status=e.status,this.tags=e.tags||{},this._traceId=e.traceId||this._traceId,this}getTraceContext(){return(0,me.kX)(this)}getSpanJSON(){return(0,a.Ce)({data:this._getData(),description:this._name,op:this._attributes[J],parent_span_id:this._parentSpanId,span_id:this._spanId,start_timestamp:this._startTime,status:this._status,tags:Object.keys(this.tags).length>0?this.tags:void 0,timestamp:this._endTime,trace_id:this._traceId,origin:this._attributes[z],_metrics_summary:Me(this),profile_id:this._attributes.profile_id,exclusive_time:this._exclusiveTime,measurements:Object.keys(this._measurements).length>0?this._measurements:void 0})}isRecording(){return!this._endTime&&!!this._sampled}toJSON(){return this.getSpanJSON()}_getData(){const{data:e,_attributes:t}=this,n=Object.keys(e).length>0,i=Object.keys(t).length>0;if(n||i)return n&&i?{...e,...t}:n?e:t}}class Lt extends Et{constructor(e,t){super(e),this._contexts={},this._hub=t||(0,ne.BF)(),this._name=e.name||"",this._metadata={...e.metadata},this._trimEnd=e.trimEnd,this.transaction=this;const n=this._metadata.dynamicSamplingContext;n&&(this._frozenDynamicSamplingContext={...n})}get name(){return this._name}set name(e){this.setName(e)}get metadata(){return{source:"custom",spanMetadata:{},...this._metadata,...this._attributes[k]&&{source:this._attributes[k]},...this._attributes[_]&&{sampleRate:this._attributes[_]}}}set metadata(e){this._metadata=e}setName(e,t="custom"){this._name=e,this.setAttribute(k,t)}updateName(e){return this._name=e,this}initSpanRecorder(e=1e3){this.spanRecorder||(this.spanRecorder=new Tt(e)),this.spanRecorder.add(this)}setContext(e,t){null===t?delete this._contexts[e]:this._contexts[e]=t}setMeasurement(e,t,n=""){this._measurements[e]={value:t,unit:n}}setMetadata(e){this._metadata={...this._metadata,...e}}end(e){const t=(0,me.cI)(e),n=this._finishTransaction(t);if(n)return this._hub.captureEvent(n)}toContext(){const e=super.toContext();return(0,a.Ce)({...e,name:this._name,trimEnd:this._trimEnd})}updateWithContext(e){return super.updateWithContext(e),this._name=e.name||"",this._trimEnd=e.trimEnd,this}getDynamicSamplingContext(){return(0,ge.k)(this)}setHub(e){this._hub=e}getProfileId(){if(void 0!==this._contexts&&void 0!==this._contexts.profile)return this._contexts.profile.profile_id}_finishTransaction(e){if(void 0!==this._endTime)return;this._name||(m.T&&p.vF.warn("Transaction has no name, falling back to ``."),this._name=""),super.end(e);const t=this._hub.getClient();if(t&&t.emit&&t.emit("finishTransaction",this),!0!==this._sampled)return m.T&&p.vF.log("[Tracing] Discarding transaction because its trace was not chosen to be sampled."),void(t&&t.recordDroppedEvent("sample_rate","transaction"));const n=this.spanRecorder?this.spanRecorder.spans.filter((e=>e!==this&&(0,me.et)(e).timestamp)):[];if(this._trimEnd&&n.length>0){const e=n.map((e=>(0,me.et)(e).timestamp)).filter(Boolean);this._endTime=e.reduce(((e,t)=>e>t?e:t))}const{scope:i,isolationScope:s}={scope:this[Xe],isolationScope:this[He]};const{metadata:o}=this,{source:r}=o,c={contexts:{...this._contexts,trace:(0,me.kX)(this)},spans:n,start_timestamp:this._startTime,tags:this.tags,timestamp:this._endTime,transaction:this._name,type:"transaction",sdkProcessingMetadata:{...o,capturedSpanScope:i,capturedSpanIsolationScope:s,...(0,a.Ce)({dynamicSamplingContext:(0,ge.k)(this)})},_metrics_summary:Me(this),...r&&{transaction_info:{source:r}}};return Object.keys(this._measurements).length>0&&(m.T&&p.vF.log("[Measurements] Adding measurements to transaction",JSON.stringify(this._measurements,void 0,2)),c.measurements=this._measurements),m.T&&p.vF.log(`[Tracing] Finishing ${this.op} transaction: ${this._name}.`),c}}function Qt(){const e=this.getScope().getSpan();return e?{"sentry-trace":(0,me.Qh)(e)}:{}}function jt(e,t){const n=this.getClient(),i=n&&n.getOptions()||{},s=i.instrumenter||"sentry",o=e.instrumenter||"sentry";s!==o&&(m.T&&p.vF.error(`A transaction was started with instrumenter=\`${o}\`, but the SDK is configured with the \`${s}\` instrumenter.\nThe transaction will not be sampled. Please use the ${s} instrumentation to start transactions.`),e.sampled=!1);let r=new Lt(e,this);return r=function(e,t,n){if(!Ze(t))return e.sampled=!1,e;if(void 0!==e.sampled)return e.setAttribute(_,Number(e.sampled)),e;let i;return"function"==typeof t.tracesSampler?(i=t.tracesSampler(n),e.setAttribute(_,Number(i))):void 0!==n.parentSampled?i=n.parentSampled:void 0!==t.tracesSampleRate?(i=t.tracesSampleRate,e.setAttribute(_,Number(i))):(i=1,e.setAttribute(_,i)),s=i,((0,f.yr)(s)||"number"!=typeof s&&"boolean"!=typeof s?(m.T&&p.vF.warn(`[Tracing] Given sample rate is invalid. Sample rate must be a boolean or a number between 0 and 1. Got ${JSON.stringify(s)} of type ${JSON.stringify(typeof s)}.`),0):!(s<0||s>1)||(m.T&&p.vF.warn(`[Tracing] Given sample rate is invalid. Sample rate must be between 0 and 1. Got ${s}.`),0))?i?(e.sampled=Math.random()0){const e=n.getRequestSession();e&&"ok"===e.status&&(e.status="errored")}return super.captureEvent(e,t,n)}close(e){return this._sessionFlusher&&this._sessionFlusher.close(),super.close(e)}initSessionFlusher(){const{release:e,environment:t}=this._options;e?this._sessionFlusher=new Rt(this,{release:e,environment:t}):m.T&&p.vF.warn("Cannot initialise an instance of SessionFlusher if no release is provided!")}captureCheckIn(e,t,n){const i="checkInId"in e&&e.checkInId?e.checkInId:(0,C.eJ)();if(!this._isEnabled())return m.T&&p.vF.warn("SDK not enabled, will not capture checkin."),i;const s=this.getOptions(),{release:o,environment:r,tunnel:c}=s,l={check_in_id:i,monitor_slug:e.monitorSlug,status:e.status,release:o,environment:r};"duration"in e&&(l.duration=e.duration),t&&(l.monitor_config={schedule:t.schedule,checkin_margin:t.checkinMargin,max_runtime:t.maxRuntime,timezone:t.timezone});const[g,d]=this._getTraceInfoFromScope(n);d&&(l.contexts={trace:d});const u=function(e,t,n,i,s){const o={sent_at:(new Date).toISOString()};n&&n.sdk&&(o.sdk={name:n.sdk.name,version:n.sdk.version}),i&&s&&(o.dsn=T(s)),t&&(o.trace=(0,a.Ce)(t));const r=function(e){return[{type:"check_in"},e]}(e);return Q(o,[r])}(l,g,this.getSdkMetadata(),c,this.getDsn());return m.T&&p.vF.info("Sending checkin:",e.monitorSlug,e.status),this._sendEnvelope(u),i}_captureRequestSession(){this._sessionFlusher?this._sessionFlusher.incrementSessionStatusCount():m.T&&p.vF.warn("Discarded request mode session because autoSessionTracking option was disabled")}_prepareEvent(e,t,n,i){return this._options.platform&&(e.platform=e.platform||this._options.platform),this._options.runtime&&(e.contexts={...e.contexts,runtime:(e.contexts||{}).runtime||this._options.runtime}),this._options.serverName&&(e.server_name=e.server_name||this._options.serverName),super._prepareEvent(e,t,n,i)}_getTraceInfoFromScope(e){if(!e)return[void 0,void 0];const t=e.getSpan();if(t)return[(0,xt.z)(t)?(0,ge.k)(t):void 0,(0,me.kX)(t)];const{traceId:n,spanId:i,parentSpanId:s,dsc:o}=e.getPropagationContext(),r={trace_id:n,span_id:i,parent_span_id:s};return o?[o,r]:[(0,ge.l)(n,this,e),r]}}class Pt extends Ot{constructor(e){!function(e,t,n=[t],i="npm"){const s=e._metadata||{};s.sdk||(s.sdk={name:`sentry.javascript.${t}`,packages:n.map((e=>({name:`${i}:@sentry/${e}`,version:Zt.M}))),version:Zt.M}),e._metadata=s}(e,"node"),e.transportOptions={textEncoder:new Vt.TextEncoder,...e.transportOptions},super({...e,platform:"node",runtime:{name:"node",version:global.process.version},serverName:e.serverName||global.process.env.SENTRY_NAME||ft.hostname()})}}function Mt(e,t){return null!=e?e:t()}var Dt=n(8611),qt=n(5692),$t=n(2203),en=n(7016);const tn=require("zlib");var nn=n(853),sn=n(9278);const on=require("tls"),rn=Symbol("AgentBaseInternalState");class an extends Dt.Agent{constructor(e){super(e),this[rn]={}}isSecureEndpoint(e){if(e){if("boolean"==typeof e.secureEndpoint)return e.secureEndpoint;if("string"==typeof e.protocol)return"https:"===e.protocol}const{stack:t}=new Error;return"string"==typeof t&&t.split("\n").some((e=>-1!==e.indexOf("(https.js:")||-1!==e.indexOf("node:https:")))}createSocket(e,t,n){const i={...t,secureEndpoint:this.isSecureEndpoint(t)};Promise.resolve().then((()=>this.connect(e,i))).then((s=>{if(s instanceof Dt.Agent)return s.addRequest(e,i);this[rn].currentSocket=s,super.createSocket(e,t,n)}),n)}createConnection(){const e=this[rn].currentSocket;if(this[rn].currentSocket=void 0,!e)throw new Error("No socket was returned in the `connect()` function");return e}get defaultPort(){return Mt(this[rn].defaultPort,(()=>"https:"===this.protocol?443:80))}set defaultPort(e){this[rn]&&(this[rn].defaultPort=e)}get protocol(){return Mt(this[rn].protocol,(()=>this.isSecureEndpoint()?"https:":"http:"))}set protocol(e){this[rn]&&(this[rn].protocol=e)}}function cn(...e){p.vF.log("[https-proxy-agent:parse-proxy-response]",...e)}function ln(...e){p.vF.log("[https-proxy-agent]",...e)}class gn extends an{static __initStatic(){this.protocols=["http","https"]}constructor(e,t){super(t),this.options={},this.proxy="string"==typeof e?new en.URL(e):e,this.proxyHeaders=Mt((0,nn.z)([t,"optionalAccess",e=>e.headers]),(()=>({}))),ln("Creating new HttpsProxyAgent instance: %o",this.proxy.href);const n=(this.proxy.hostname||this.proxy.host).replace(/^\[|\]$/g,""),i=this.proxy.port?parseInt(this.proxy.port,10):"https:"===this.proxy.protocol?443:80;this.connectOpts={ALPNProtocols:["http/1.1"],...t?un(t,"headers"):null,host:n,port:i}}async connect(e,t){const{proxy:n}=this;if(!t.host)throw new TypeError('No "host" provided');let i;if("https:"===n.protocol){ln("Creating `tls.Socket`: %o",this.connectOpts);const e=this.connectOpts.servername||this.connectOpts.host;i=on.connect({...this.connectOpts,servername:e&&sn.isIP(e)?void 0:e})}else ln("Creating `net.Socket`: %o",this.connectOpts),i=sn.connect(this.connectOpts);const s="function"==typeof this.proxyHeaders?this.proxyHeaders():{...this.proxyHeaders},o=sn.isIPv6(t.host)?`[${t.host}]`:t.host;let r=`CONNECT ${o}:${t.port} HTTP/1.1\r\n`;if(n.username||n.password){const e=`${decodeURIComponent(n.username)}:${decodeURIComponent(n.password)}`;s["Proxy-Authorization"]=`Basic ${Buffer.from(e).toString("base64")}`}s.Host=`${o}:${t.port}`,s["Proxy-Connection"]||(s["Proxy-Connection"]=this.keepAlive?"Keep-Alive":"close");for(const e of Object.keys(s))r+=`${e}: ${s[e]}\r\n`;const a=function(e){return new Promise(((t,n)=>{let i=0;const s=[];function o(){const a=e.read();a?function(a){s.push(a),i+=a.length;const c=Buffer.concat(s,i),l=c.indexOf("\r\n\r\n");if(-1===l)return cn("have not received end of HTTP headers yet..."),void o();const g=c.slice(0,l).toString("ascii").split("\r\n"),d=g.shift();if(!d)return e.destroy(),n(new Error("No header received from proxy CONNECT response"));const u=d.split(" "),b=+u[1],I=u.slice(2).join(" "),p={};for(const t of g){if(!t)continue;const i=t.indexOf(":");if(-1===i)return e.destroy(),n(new Error(`Invalid header from proxy CONNECT response: "${t}"`));const s=t.slice(0,i).toLowerCase(),o=t.slice(i+1).trimStart(),r=p[s];"string"==typeof r?p[s]=[r,o]:Array.isArray(r)?r.push(o):p[s]=o}cn("got proxy server response: %o %o",d,p),r(),t({connect:{statusCode:b,statusText:I,headers:p},buffered:c})}(a):e.once("readable",o)}function r(){e.removeListener("end",a),e.removeListener("error",c),e.removeListener("readable",o)}function a(){r(),cn("onend"),n(new Error("Proxy connection ended before receiving CONNECT response"))}function c(e){r(),cn("onerror %o",e),n(e)}e.on("error",c),e.on("end",a),o()}))}(i);i.write(`${r}\r\n`);const{connect:c,buffered:l}=await a;if(e.emit("proxyConnect",c),this.emit("proxyConnect",c,e),200===c.statusCode){if(e.once("socket",dn),t.secureEndpoint){ln("Upgrading socket connection to TLS");const e=t.servername||t.host;return on.connect({...un(t,"host","path","port"),socket:i,servername:sn.isIP(e)?void 0:e})}return i}i.destroy();const g=new sn.Socket({writable:!1});return g.readable=!0,e.once("socket",(e=>{ln("Replaying proxy buffer for failed request"),e.push(l),e.push(null)})),g}}function dn(e){e.resume()}function un(e,...t){const n={};let i;for(i in e)t.includes(i)||(n[i]=e[i]);return n}gn.__initStatic();const bn=32768;function In(e){let t;try{t=new en.URL(e.url)}catch(t){return(0,p.pq)((()=>{console.warn("[@sentry/node]: Invalid dsn or tunnel option, will not send any events. The tunnel option must be a full URL when used.")})),we(e,(()=>Promise.resolve({})))}const n="https:"===t.protocol,i=function(e,t){const{no_proxy:n}=process.env;return n&&n.split(",").some((t=>e.host.endsWith(t)||e.hostname.endsWith(t)))?void 0:t}(t,e.proxy||(n?process.env.https_proxy:void 0)||process.env.http_proxy),s=n?qt:Dt,o=void 0!==e.keepAlive&&e.keepAlive,r=i?new gn(i):new s.Agent({keepAlive:o,maxSockets:30,timeout:2e3}),a=function(e,t,n){const{hostname:i,pathname:s,port:o,protocol:r,search:a}=new en.URL(e.url);return function(c){return new Promise(((l,g)=>{let d=function(e){return new $t.Readable({read(){this.push(e),this.push(null)}})}(c.body);const u={...e.headers};c.body.length>bn&&(u["content-encoding"]="gzip",d=d.pipe((0,tn.createGzip)()));const b=t.request({method:"POST",agent:n,headers:u,hostname:i,path:`${s}${a}`,port:o,protocol:r,ca:e.caCerts},(e=>{e.on("data",(()=>{})),e.on("end",(()=>{})),e.setEncoding("utf8");const t=Mt(e.headers["retry-after"],(()=>null)),n=Mt(e.headers["x-sentry-rate-limits"],(()=>null));l({statusCode:e.statusCode,headers:{"retry-after":t,"x-sentry-rate-limits":Array.isArray(n)?n[0]:n}})}));b.on("error",g),d.pipe(b)}))}}(e,Mt(e.httpModule,(()=>s)),r);return we(e,a)}var pn=n(3245);const Cn=require("domain");function hn(){return Cn.active}function mn(){const e=hn();if(e)return(0,ne.TF)(e),(0,ne.Me)(e)}function yn(e,t){const n=hn();if(n&&(0,nn.z)([t,"optionalAccess",e=>e.reuseExisting]))return e();const i=Cn.create(),s=function(e){const t={};return(0,ne.TF)(t,e),(0,ne.Me)(t)}(n?(0,ne.Me)(n):void 0);return(0,ne.lq)(i,s),i.bind((()=>e()))()}const Zn=require("async_hooks");let Gn;function Bn(){pn.S.major>=14?function(){function e(){return Gn.getStore()}Gn||(Gn=new Zn.AsyncLocalStorage),(0,ne.nX)({getCurrentHub:e,runWithAsyncContext:function(t,n){const i=e();if(i&&(0,nn.z)([n,"optionalAccess",e=>e.reuseExisting]))return t();const s=function(e){const t={};return(0,ne.TF)(t,e),(0,ne.Me)(t)}(i);return Gn.run(s,(()=>t()))}})}():(0,ne.nX)({getCurrentHub:mn,runWithAsyncContext:yn})}function An(e){const t="console";Nt(t,e),wt(t,Wn)}function Wn(){"console"in Yt.OW&&p.Ow.forEach((function(e){e in Yt.OW.console&&(0,a.GS)(Yt.OW.console,e,(function(t){return p.Z9[e]=t,function(...t){Kt("console",{args:t,level:e});const n=p.Z9[e];n&&n.apply(Yt.OW.console,t)}}))}))}const fn=["fatal","error","warning","log","info","debug"];function Vn(e){return"warn"===e?"warning":fn.includes(e)?e:"log"}const vn="Console",Rn=(0,l._C)((()=>({name:vn,setupOnce(){},setup(e){An((({args:t,level:n})=>{(0,c.KU)()===e&&(0,c.ZQ)({category:"console",level:Vn(n),message:Vt.format.apply(void 0,t)},{input:[...t],level:n})}))}}))),Yn=(0,l.F)(vn,Rn),Xn=require("child_process"),Hn=require("fs");var Sn=n(6928);const Nn=(0,Vt.promisify)(Hn.readFile),wn=(0,Vt.promisify)(Hn.readdir),Kn="Context",Fn=(0,l._C)(((e={})=>{let t;const n={app:!0,os:!0,device:!0,culture:!0,cloudResource:!0,...e};return{name:Kn,setupOnce(){},processEvent:e=>async function(e){void 0===t&&(t=async function(){const e={};if(n.os&&(e.os=await async function(){const e=ft.platform();switch(e){case"darwin":return async function(){const e={kernel_version:ft.release(),name:"Mac OS X",version:"10."+(Number(ft.release().split(".")[0])-4)};try{const t=await new Promise(((e,t)=>{(0,Xn.execFile)("/usr/bin/sw_vers",((n,i)=>{n?t(n):e(i)}))}));e.name=Un(/^ProductName:\s+(.*)$/m,t),e.version=Un(/^ProductVersion:\s+(.*)$/m,t),e.build=Un(/^BuildVersion:\s+(.*)$/m,t)}catch(e){}return e}();case"linux":return async function(){const e={kernel_version:ft.release(),name:"Linux"};try{const t=await wn("/etc"),n=Jn.find((e=>t.includes(e.name)));if(!n)return e;const i=(0,Sn.join)("/etc",n.name),s=(await Nn(i,{encoding:"utf-8"})).toLowerCase(),{distros:o}=n;e.name=o.find((e=>s.indexOf(xn(e))>=0))||o[0];const r=xn(e.name);e.version=zn[r](s)}catch(e){}return e}();default:return{name:_n[e]||e,version:ft.release()}}}()),n.app&&(e.app=function(){const e=process.memoryUsage().rss;return{app_start_time:new Date(Date.now()-1e3*process.uptime()).toISOString(),app_memory:e}}()),n.device&&(e.device=function(e){const t={};let n;try{n=ft.uptime&&ft.uptime()}catch(e){}if("number"==typeof n&&(t.boot_time=new Date(Date.now()-1e3*n).toISOString()),t.arch=ft.arch(),(!0===e||e.memory)&&(t.memory_size=ft.totalmem(),t.free_memory=ft.freemem()),!0===e||e.cpu){const e=ft.cpus();if(e&&e.length){const n=e[0];t.processor_count=e.length,t.cpu_description=n.model,t.processor_frequency=n.speed}}return t}(n.device)),n.culture){const t=function(){try{if("string"!=typeof process.versions.icu)return;const e=new Date(9e8);if("enero"===new Intl.DateTimeFormat("es",{month:"long"}).format(e)){const e=Intl.DateTimeFormat().resolvedOptions();return{locale:e.locale,timezone:e.timeZone}}}catch(e){}}();t&&(e.culture=t)}return n.cloudResource&&(e.cloud_resource=process.env.VERCEL?{"cloud.provider":"vercel","cloud.region":process.env.VERCEL_REGION}:process.env.AWS_REGION?{"cloud.provider":"aws","cloud.region":process.env.AWS_REGION,"cloud.platform":process.env.AWS_EXECUTION_ENV}:process.env.GCP_PROJECT?{"cloud.provider":"gcp"}:process.env.ALIYUN_REGION_ID?{"cloud.provider":"alibaba_cloud","cloud.region":process.env.ALIYUN_REGION_ID}:process.env.WEBSITE_SITE_NAME&&process.env.REGION_NAME?{"cloud.provider":"azure","cloud.region":process.env.REGION_NAME}:process.env.IBM_CLOUD_REGION?{"cloud.provider":"ibm_cloud","cloud.region":process.env.IBM_CLOUD_REGION}:process.env.TENCENTCLOUD_REGION?{"cloud.provider":"tencent_cloud","cloud.region":process.env.TENCENTCLOUD_REGION,"cloud.account.id":process.env.TENCENTCLOUD_APPID,"cloud.availability_zone":process.env.TENCENTCLOUD_ZONE}:process.env.NETLIFY?{"cloud.provider":"netlify"}:process.env.FLY_REGION?{"cloud.provider":"fly.io","cloud.region":process.env.FLY_REGION}:process.env.DYNO?{"cloud.provider":"heroku"}:void 0),e}());const i=(s=await t,(0,nn.z)([s,"optionalAccess",e=>e.app,"optionalAccess",e=>e.app_memory])&&(s.app.app_memory=process.memoryUsage().rss),(0,nn.z)([s,"optionalAccess",e=>e.device,"optionalAccess",e=>e.free_memory])&&(s.device.free_memory=ft.freemem()),s);var s;return e.contexts={...e.contexts,app:{...i.app,...(0,nn.z)([e,"access",e=>e.contexts,"optionalAccess",e=>e.app])},os:{...i.os,...(0,nn.z)([e,"access",e=>e.contexts,"optionalAccess",e=>e.os])},device:{...i.device,...(0,nn.z)([e,"access",e=>e.contexts,"optionalAccess",e=>e.device])},culture:{...i.culture,...(0,nn.z)([e,"access",e=>e.contexts,"optionalAccess",e=>e.culture])},cloud_resource:{...i.cloud_resource,...(0,nn.z)([e,"access",e=>e.contexts,"optionalAccess",e=>e.cloud_resource])}},e}(e)}})),kn=(0,l.F)(Kn,Fn),_n={aix:"IBM AIX",freebsd:"FreeBSD",openbsd:"OpenBSD",sunos:"SunOS",win32:"Windows"},Jn=[{name:"fedora-release",distros:["Fedora"]},{name:"redhat-release",distros:["Red Hat Linux","Centos"]},{name:"redhat_version",distros:["Red Hat Linux"]},{name:"SuSE-release",distros:["SUSE Linux"]},{name:"lsb-release",distros:["Ubuntu Linux","Arch Linux"]},{name:"debian_version",distros:["Debian"]},{name:"debian_release",distros:["Debian"]},{name:"arch-release",distros:["Arch Linux"]},{name:"gentoo-release",distros:["Gentoo Linux"]},{name:"novell-release",distros:["SUSE Linux"]},{name:"alpine-release",distros:["Alpine Linux"]}],zn={alpine:e=>e,arch:e=>Un(/distrib_release=(.*)/,e),centos:e=>Un(/release ([^ ]+)/,e),debian:e=>e,fedora:e=>Un(/release (..)/,e),mint:e=>Un(/distrib_release=(.*)/,e),red:e=>Un(/release ([^ ]+)/,e),suse:e=>Un(/VERSION = (.*)\n/,e),ubuntu:e=>Un(/distrib_release=(.*)/,e)};function Un(e,t){const n=e.exec(t);return n?n[1]:void 0}function xn(e){return e.split(" ")[0].toLowerCase()}class Tn{constructor(e){this._maxSize=e,this._cache=new Map}get size(){return this._cache.size}get(e){const t=this._cache.get(e);if(void 0!==t)return this._cache.delete(e),this._cache.set(e,t),t}set(e,t){this._cache.size>=this._maxSize&&this._cache.delete(this._cache.keys().next().value),this._cache.set(e,t)}remove(e){const t=this._cache.get(e);return t&&this._cache.delete(e),t}clear(){this._cache.clear()}keys(){return Array.from(this._cache.keys())}values(){const e=[];return this._cache.forEach((t=>e.push(t))),e}}const En=new Tn(100),Ln="ContextLines",Qn=(0,l._C)(((e={})=>{const t=void 0!==e.frameContextLines?e.frameContextLines:7;return{name:Ln,setupOnce(){},processEvent:e=>async function(e,t){const n={},i=[];if(t>0&&(0,nn.z)([e,"access",e=>e.exception,"optionalAccess",e=>e.values]))for(const t of e.exception.values)if((0,nn.z)([t,"access",e=>e.stacktrace,"optionalAccess",e=>e.frames]))for(let e=t.stacktrace.frames.length-1;e>=0;e--){const s=t.stacktrace.frames[e];!s.filename||n[s.filename]||En.get(s.filename)||(i.push(Pn(s.filename)),n[s.filename]=1)}if(i.length>0&&await Promise.all(i),t>0&&(0,nn.z)([e,"access",e=>e.exception,"optionalAccess",e=>e.values]))for(const n of e.exception.values)n.stacktrace&&n.stacktrace.frames&&await On(n.stacktrace.frames,t);return e}(e,t)}})),jn=(0,l.F)(Ln,Qn);function On(e,t){for(const n of e)if(n.filename&&void 0===n.context_line){const e=En.get(n.filename);if(e)try{(0,C.db)(e,n,t)}catch(e){}}}async function Pn(e){const t=En.get(e);if(null===t)return null;if(void 0!==t)return t;let n=null;try{const t=await(i=e,new Promise(((e,t)=>{(0,Hn.readFile)(i,"utf8",((n,i)=>{n?t(n):e(i)}))})));n=t.split("\n")}catch(e){}var i;return En.set(e,n),n}function Mn(e,t){const n=t&&function(e){return void 0!==e.getClient}(t)?t.getClient():t,i=n&&n.getDsn(),s=n&&n.getOptions().tunnel;return function(e,t){return!!t&&e.includes(t.host)}(e,i)||function(e,t){return!!t&&Dn(e)===Dn(t)}(e,s)}function Dn(e){return"/"===e[e.length-1]?e.slice(0,-1):e}var qn=n(5584);const $n="undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__;function ei(e){const{protocol:t,hostname:n,port:i}=ii(e),s=e.pathname||"/";return`${t}//${e.auth?function(e){const[t,n]=e.split(":");return`${t?"[Filtered]":""}:${n?"[Filtered]":""}@`}(e.auth):""}${n}${i}${s}`}function ti(e,t,n){if(!e)return e;let[i,s]=e.split(" ");return t.host&&!t.protocol&&(t.protocol=(0,nn.z)([n,"optionalAccess",e=>e.agent,"optionalAccess",e=>e.protocol]),s=ei(t)),(0,nn.z)([s,"optionalAccess",e=>e.startsWith,"call",e=>e("///")])&&(s=s.slice(2)),`${i} ${s}`}function ni(e){const t={protocol:e.protocol,hostname:"string"==typeof e.hostname&&e.hostname.startsWith("[")?e.hostname.slice(1,-1):e.hostname,hash:e.hash,search:e.search,pathname:e.pathname,path:`${e.pathname||""}${e.search||""}`,href:e.href};return""!==e.port&&(t.port=Number(e.port)),(e.username||e.password)&&(t.auth=`${e.username}:${e.password}`),t}function ii(e){const t=e.protocol||"",n=e.hostname||e.host||"";return{protocol:t,hostname:n,port:!e.port||80===e.port||443===e.port||/^(.*):(\d+)$/.test(n)?"":`:${e.port}`}}const si=(0,l._C)(((e={})=>{const{breadcrumbs:t,tracing:n,shouldCreateSpanForRequest:i}=e,s={breadcrumbs:t,tracing:!1!==n&&(0,a.Ce)({enableIfHasTracingEnabled:!0!==n||void 0,shouldCreateSpanForRequest:i})};return new oi(s)}));class oi{static __initStatic(){this.id="Http"}__init(){this.name=oi.id}constructor(e={}){oi.prototype.__init.call(this),this._breadcrumbs=void 0===e.breadcrumbs||e.breadcrumbs,this._tracing=e.tracing?!0===e.tracing?{}:e.tracing:void 0}setupOnce(e,t){const i=(0,nn.z)([t,"call",e=>e(),"access",e=>e.getClient,"call",e=>e(),"optionalAccess",e=>e.getOptions,"call",e=>e()]),s=function(e,t){return void 0!==e&&(!e.enableIfHasTracingEnabled||Ze(t))}(this._tracing,i);if(!this._breadcrumbs&&!s)return;if(i&&"sentry"!==i.instrumenter)return void($n&&p.vF.log("HTTP Integration is skipped because of instrumenter configuration."));const o=function(e,t,n){return e?(0,nn.z)([t,"optionalAccess",e=>e.shouldCreateSpanForRequest])||(0,nn.z)([n,"optionalAccess",e=>e.shouldCreateSpanForRequest]):()=>!1}(s,this._tracing,i),r=(0,nn.z)([i,"optionalAccess",e=>e.tracePropagationTargets])||(0,nn.z)([this,"access",e=>e._tracing,"optionalAccess",e=>e.tracePropagationTargets]),c=n(8611),l=ri(c,this._breadcrumbs,o,r);if((0,a.GS)(c,"get",l),(0,a.GS)(c,"request",l),pn.S.major>8){const e=n(5692),t=ri(e,this._breadcrumbs,o,r);(0,a.GS)(e,"get",t),(0,a.GS)(e,"request",t)}}}function ri(e,t,n,i){const s=new Tn(100),o=new Tn(100);function r(e,t,n,i){(0,ne.BF)().getIntegration(oi)&&(0,c.ZQ)({category:"http",data:{status_code:i&&i.statusCode,...t},type:"http"},{event:e,request:n,response:i})}return function(a){return function(...l){const g=function(e,t){let n,i;if("function"==typeof t[t.length-1]&&(n=t.pop()),"string"==typeof t[0])i=ni(new en.URL(t[0]));else if(t[0]instanceof en.URL)i=ni(t[0]);else{i=t[0];try{const e=new en.URL(i.path||"",`${i.protocol||"http:"}//${i.hostname}`);i={pathname:e.pathname,search:e.search,hash:e.hash,...i}}catch(e){}}return 2===t.length&&(i={...i,...t[1]}),void 0===i.protocol&&(pn.S.major>8?i.protocol=(0,nn.z)([(0,nn.z)([e,"optionalAccess",e=>e.globalAgent]),"optionalAccess",e=>e.protocol])||(0,nn.z)([i.agent,"optionalAccess",e=>e.protocol])||(0,nn.z)([i._defaultAgent,"optionalAccess",e=>e.protocol]):i.protocol=(0,nn.z)([i.agent,"optionalAccess",e=>e.protocol])||(0,nn.z)([i._defaultAgent,"optionalAccess",e=>e.protocol])||(0,nn.z)([(0,nn.z)([e,"optionalAccess",e=>e.globalAgent]),"optionalAccess",e=>e.protocol])),n?[i,n]:[i]}(e,l),d=g[0],u=function(e){const{protocol:t,hostname:n,port:i}=ii(e);return`${t}//${n}${i}${e.path?e.path:"/"}`}(d),b=ei(d),I=(0,c.KU)();if(Mn(b,I))return a.apply(e,g);const C=(0,c.o5)(),m=(0,ne.rm)(),y=Ve(),Z=function(e,t){const n={url:e,"http.method":t.method||"GET"};return t.hash&&(n["http.fragment"]=t.hash.substring(1)),t.search&&(n["http.query"]=t.search.substring(1)),n}(b,d),G=(e=>{if(void 0===n)return!0;const t=s.get(e);if(void 0!==t)return t;const i=n(e);return s.set(e,i),i})(u)?(0,nn.z)([y,"optionalAccess",e=>e.startChild,"call",e=>e({op:"http.client",origin:"auto.http.node.http",description:`${Z["http.method"]} ${Z.url}`,data:Z})]):void 0;if(I&&(e=>{if(void 0===i)return!0;const t=o.get(e);if(void 0!==t)return t;const n=(0,h.Xr)(e,i);return o.set(e,n),n})(u)){const{traceId:e,spanId:t,sampled:n,dsc:i}={...m.getPropagationContext(),...C.getPropagationContext()},s=G?(0,me.Qh)(G):(0,he.TC)(e,t,n),o=(0,qn.De)(i||(G?(0,ge.k)(G):(0,ge.l)(e,I,C)));!function(e,t,n,i){(e.headers||{})["sentry-trace"]||($n&&p.vF.log(`[Tracing] Adding sentry-trace header ${n} to outgoing request to "${t}": `),e.headers={...e.headers,"sentry-trace":n,...i&&i.length>0&&{baggage:ai(e,i)}})}(d,b,s,o)}else $n&&p.vF.log(`[Tracing] Not adding sentry-trace header to outgoing request (${b}) due to mismatching tracePropagationTargets option.`);return a.apply(e,g).once("response",(function(e){t&&r("response",Z,this,e),G&&(e.statusCode&&Ue(G,e.statusCode),G.updateName(ti((0,me.et)(G).description||"",d,this)||""),G.end())})).once("error",(function(){t&&r("error",Z,this),G&&(Ue(G,500),G.updateName(ti((0,me.et)(G).description||"",d,this)||""),G.end())}))}}}function ai(e,t){return e.headers&&e.headers.baggage?t?Array.isArray(e.headers.baggage)?[...e.headers.baggage,t]:[e.headers.baggage,t]:e.headers.baggage:t}function ci(e){return void 0!==e&&(0===e.length||"?"===e||""===e)}function li(e){if(void 0!==e)return e.slice(-10).reduce(((e,t)=>`${e},${t.function},${t.lineno},${t.colno}`),"")}function gi(e){let t=[],n=!1;function i(i){t=[],n||(n=!0,e(i))}return t.push(i),{add:function(e){t.push(e)},next:function(e){const n=t.pop()||i;try{n(e)}catch(t){i(e)}}}}oi.__initStatic();class di{constructor(){const{Session:e}=n(264);this._session=new e}configureAndConnect(e,t){this._session.connect(),this._session.on("Debugger.paused",(t=>{e(t,(()=>{this._session.post("Debugger.resume")}))})),this._session.post("Debugger.enable"),this._session.post("Debugger.setPauseOnExceptions",{state:t?"all":"uncaught"})}setPauseOnExceptions(e){this._session.post("Debugger.setPauseOnExceptions",{state:e?"all":"uncaught"})}getLocalVariables(e,t){this._getProperties(e,(e=>{const{add:n,next:i}=gi(t);for(const t of e)if((0,nn.z)([t,"optionalAccess",e=>e.value,"optionalAccess",e=>e.objectId])&&"Array"===(0,nn.z)([t,"optionalAccess",e=>e.value,"access",e=>e.className])){const e=t.value.objectId;n((n=>this._unrollArray(e,t.name,n,i)))}else if((0,nn.z)([t,"optionalAccess",e=>e.value,"optionalAccess",e=>e.objectId])&&"Object"===(0,nn.z)([t,"optionalAccess",e=>e.value,"optionalAccess",e=>e.className])){const e=t.value.objectId;n((n=>this._unrollObject(e,t.name,n,i)))}else null==(0,nn.z)([t,"optionalAccess",e=>e.value,"optionalAccess",e=>e.value])&&null==(0,nn.z)([t,"optionalAccess",e=>e.value,"optionalAccess",e=>e.description])||n((e=>this._unrollOther(t,e,i)));i({})}))}_getProperties(e,t){this._session.post("Runtime.getProperties",{objectId:e,ownProperties:!0},((e,n)=>{t(e?[]:n.result)}))}_unrollArray(e,t,n,i){this._getProperties(e,(e=>{n[t]=e.filter((e=>"length"!==e.name&&!isNaN(parseInt(e.name,10)))).sort(((e,t)=>parseInt(e.name,10)-parseInt(t.name,10))).map((e=>(0,nn.z)([e,"optionalAccess",e=>e.value,"optionalAccess",e=>e.value]))),i(n)}))}_unrollObject(e,t,n,i){this._getProperties(e,(e=>{n[t]=e.map((e=>[e.name,(0,nn.z)([e,"optionalAccess",e=>e.value,"optionalAccess",e=>e.value])])).reduce(((e,[t,n])=>(e[t]=n,e)),{}),i(n)}))}_unrollOther(e,t,n){null!=(0,nn.z)([e,"optionalAccess",e=>e.value,"optionalAccess",e=>e.value])?t[e.name]=e.value.value:null!=(0,nn.z)([e,"optionalAccess",e=>e.value,"optionalAccess",e=>e.description])&&"function"!==(0,nn.z)([e,"optionalAccess",e=>e.value,"optionalAccess",e=>e.type])&&(t[e.name]=`<${e.value.description}>`),n(t)}}const ui="LocalVariables",bi=(0,l._C)(((e={},t=function(){try{return new di}catch(e){return}}())=>{const n=new Tn(20);let i,s=!1;function o(e){const t=li((0,nn.z)([e,"optionalAccess",e=>e.stacktrace,"optionalAccess",e=>e.frames]));if(void 0===t)return;const i=n.remove(t);if(void 0===i)return;const s=((0,nn.z)([e,"access",e=>e.stacktrace,"optionalAccess",e=>e.frames])||[]).filter((e=>"new Promise"!==e.function));for(let e=0;ee.getOptions,"call",e=>e()]);if(t&&(0,nn.z)([r,"optionalAccess",e=>e.includeLocalVariables])){if(pn.S.major<18)return void p.vF.log("The `LocalVariables` integration is only supported on Node >= v18.");const o=!1!==e.captureAllExceptions;if(t.configureAndConnect(((e,s)=>function(e,{params:{reason:s,data:o,callFrames:r}},a){if("exception"!==s&&"promiseRejection"!==s)return void a();(0,nn.z)([i,"optionalCall",e=>e()]);const c=function(e,t){if(void 0!==t)return li(e(t,1))}(e,(0,nn.z)([o,"optionalAccess",e=>e.description]));if(null==c)return void a();const{add:l,next:g}=gi((e=>{n.set(c,e),a()}));for(let e=0;e"local"===e.type)),a="global"!==s.className&&s.className?`${s.className}.${i}`:i;if(void 0===(0,nn.z)([o,"optionalAccess",e=>e.object,"access",e=>e.objectId]))l((t=>{t[e]={function:a},g(t)}));else{const n=o.object.objectId;l((i=>(0,nn.z)([t,"optionalAccess",e=>e.getLocalVariables,"call",t=>t(n,(t=>{i[e]={function:a,vars:t},g(i)}))])))}}g([])}(r.stackParser,e,s)),o),o){const n=e.maxExceptionsPerSecond||50;i=function(e){let n=0,i=5,s=0;return setInterval((()=>{var o;0===s?n>e&&(i*=2,o=i,p.vF.log(`Local variables rate-limit exceeded. Disabling capturing of caught exceptions for ${o} seconds.`),(0,nn.z)([t,"optionalAccess",e=>e.setPauseOnExceptions,"call",e=>e(!1)]),i>86400&&(i=86400),s=i):(s-=1,0===s&&(p.vF.log("Local variables rate-limit lifted."),(0,nn.z)([t,"optionalAccess",e=>e.setPauseOnExceptions,"call",e=>e(!0)]))),n=0}),1e3).unref(),()=>{n+=1}}(n)}s=!0}},processEvent:e=>s?function(e){for(const t of(0,nn.z)([e,"optionalAccess",e=>e.exception,"optionalAccess",e=>e.values])||[])o(t);return e}(e):e,_getCachedFramesCount:()=>n.size,_getFirstCachedFrame:()=>n.values()[0]}})),Ii=(0,l.F)(ui,bi),pi=bi;let Ci;const hi="Modules";function mi(){const e=n.c[n.s]&&n.c[n.s].paths||[],t=function(){try{return n.c?Object.keys(n.c):[]}catch(e){return[]}}(),i={},s={};return t.forEach((t=>{let n=t;const o=()=>{const t=n;if(n=(0,Sn.dirname)(t),!n||t===n||s[t])return;if(e.indexOf(n)<0)return o();const r=(0,Sn.join)(t,"package.json");if(s[t]=!0,!(0,Hn.existsSync)(r))return o();try{const e=JSON.parse((0,Hn.readFileSync)(r,"utf8"));i[e.name]=e.version}catch(e){}};o()})),i}const yi=(0,l._C)((()=>({name:hi,setupOnce(){},processEvent:e=>(e.modules={...e.modules,...(Ci||(Ci=mi()),Ci)},e)}))),Zi=(0,l.F)(hi,yi);function Gi(e){(0,p.pq)((()=>{console.error(e)}));const t=(0,c.KU)();void 0===t&&($n&&p.vF.warn("No NodeClient was defined, we are exiting the process now."),global.process.exit(1));const n=t.getOptions(),i=n&&n.shutdownTimeout&&n.shutdownTimeout>0&&n.shutdownTimeout||2e3;t.close(i).then((e=>{e||$n&&p.vF.warn("We reached the timeout for emptying the request buffer, still exiting now!"),global.process.exit(1)}),(e=>{$n&&p.vF.error(e)}))}const Bi="OnUncaughtException",Ai=(0,l._C)(((e={})=>{const t={exitEvenIfOtherHandlersAreRegistered:!0,...e};return{name:Bi,setupOnce(){},setup(e){global.process.on("uncaughtException",function(e,t){let n,i=!1,s=!1,o=!1;const r=e.getOptions();return Object.assign((a=>{let l=Gi;t.onFatalError?l=t.onFatalError:r.onFatalError&&(l=r.onFatalError);const g=0===global.process.listeners("uncaughtException").reduce(((e,t)=>"domainUncaughtExceptionClear"===t.name||t.tag&&"sentry_tracingErrorCallback"===t.tag||t._errorHandler?e:e+1),0),d=t.exitEvenIfOtherHandlersAreRegistered||g;i?d&&(o?($n&&p.vF.warn("uncaught exception after calling fatal error shutdown callback - this is bad! forcing shutdown"),Gi(a)):s||(s=!0,setTimeout((()=>{o||(o=!0,l(n,a))}),2e3))):(n=a,i=!0,(0,c.KU)()===e&&(0,c.Cp)(a,{originalException:a,captureContext:{level:"fatal"},mechanism:{handled:!1,type:"onuncaughtexception"}}),!o&&d&&(o=!0,l(a)))}),{_errorHandler:!0})}(e,t))}}})),Wi=(0,l.F)(Bi,Ai),fi="OnUnhandledRejection",Vi=(0,l._C)(((e={})=>{const t=e.mode||"warn";return{name:fi,setupOnce(){},setup(e){global.process.on("unhandledRejection",function(e,t){return function(n,i){(0,c.KU)()===e&&((0,c.Cp)(n,{originalException:i,captureContext:{extra:{unhandledPromiseRejection:!0}},mechanism:{handled:!1,type:"onunhandledrejection"}}),function(e,t){const n="This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:";"warn"===t.mode?(0,p.pq)((()=>{console.warn(n),console.error(e&&e.stack?e.stack:e)})):"strict"===t.mode&&((0,p.pq)((()=>{console.warn(n)})),Gi(e))}(n,t))}}(e,{mode:t}))}}})),vi=(0,l.F)(fi,Vi),Ri="Spotlight",Yi=(0,l._C)(((e={})=>{const t={sidecarUrl:e.sidecarUrl||"http://localhost:8969/stream"};return{name:Ri,setupOnce(){},setup(e){"object"==typeof process&&process.env&&p.vF.warn("[Spotlight] It seems you're not in dev mode. Do you really want to have Spotlight enabled?"),function(e,t){const n=function(e){try{return new en.URL(`${e}`)}catch(t){return void p.vF.warn(`[Spotlight] Invalid sidecar URL: ${e}`)}}(t.sidecarUrl);if(!n)return;let i=0;"function"==typeof e.on?e.on("beforeEnvelope",(e=>{if(i>3)return void p.vF.warn("[Spotlight] Disabled Sentry -> Spotlight integration due to too many failed requests");const t=M(e),s=function(){const{request:e}=Dt;return"__sentry_original__"in e?e.__sentry_original__:e}()({method:"POST",path:n.pathname,hostname:n.hostname,port:n.port,headers:{"Content-Type":"application/x-sentry-envelope"}},(e=>{e.on("data",(()=>{})),e.on("end",(()=>{})),e.setEncoding("utf8")}));s.on("error",(()=>{i++,p.vF.warn("[Spotlight] Failed to send envelope to Spotlight Sidecar")})),s.write(t),s.end()})):p.vF.warn("[Spotlight] Cannot connect to spotlight due to missing method on SDK client (`client.on`)")}(e,t)}}})),Xi=(0,l.F)(Ri,Yi);var Hi;!function(e){e.RequestCreate="undici:request:create",e.RequestEnd="undici:request:headers",e.RequestError="undici:request:error"}(Hi||(Hi={}));const Si=(0,l._C)((e=>new Ni(e)));class Ni{static __initStatic(){this.id="Undici"}__init(){this.name=Ni.id}__init2(){this._createSpanUrlMap=new Tn(100)}__init3(){this._headersUrlMap=new Tn(100)}constructor(e={}){Ni.prototype.__init.call(this),Ni.prototype.__init2.call(this),Ni.prototype.__init3.call(this),Ni.prototype.__init4.call(this),Ni.prototype.__init5.call(this),Ni.prototype.__init6.call(this),this._options={breadcrumbs:void 0===e.breadcrumbs||e.breadcrumbs,tracing:e.tracing,shouldCreateSpanForRequest:e.shouldCreateSpanForRequest}}setupOnce(e){if(pn.S.major<16)return;let t;try{t=n(1637)}catch(e){}t&&t.subscribe&&(t.subscribe(Hi.RequestCreate,this._onRequestCreate),t.subscribe(Hi.RequestEnd,this._onRequestEnd),t.subscribe(Hi.RequestError,this._onRequestError))}_shouldCreateSpan(e){if(!1===this._options.tracing||void 0===this._options.tracing&&!Ze())return!1;if(void 0===this._options.shouldCreateSpanForRequest)return!0;const t=this._createSpanUrlMap.get(e);if(void 0!==t)return t;const n=this._options.shouldCreateSpanForRequest(e);return this._createSpanUrlMap.set(e,n),n}__init4(){this._onRequestCreate=e=>{if(!(0,nn.z)([c.KU,"call",e=>e(),"optionalAccess",e=>e.getIntegration,"call",e=>e(Ni)]))return;const{request:t}=e,n=t.origin?t.origin.toString()+t.path:t.path,i=(0,c.KU)();if(!i)return;if(Mn(n,i)||void 0!==t.__sentry_span__)return;const s=i.getOptions(),o=(0,c.o5)(),r=(0,ne.rm)(),a=Ve(),l=this._shouldCreateSpan(n)?function(e,t,n){const i=function(e){if(!e)return{};const t=e.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)return{};const n=t[6]||"",i=t[8]||"";return{host:t[4],path:t[5],protocol:t[2],search:n,hash:i,relative:t[5]+n+i}}(n),s=t.method||"GET",o={"http.method":s};return i.search&&(o["http.query"]=i.search),i.hash&&(o["http.fragment"]=i.hash),(0,nn.z)([e,"optionalAccess",e=>e.startChild,"call",e=>e({op:"http.client",origin:"auto.http.node.undici",description:`${s} ${rt(i)}`,data:o})])}(a,t,n):void 0;if(l&&(t.__sentry_span__=l),(e=>{if(void 0===s.tracePropagationTargets)return!0;const t=this._headersUrlMap.get(e);if(void 0!==t)return t;const n=(0,h.Xr)(e,s.tracePropagationTargets);return this._headersUrlMap.set(e,n),n})(n)){const{traceId:e,spanId:n,sampled:s,dsc:a}={...r.getPropagationContext(),...o.getPropagationContext()};!function(e,t,n){let i;i=Array.isArray(e.headers)?e.headers.some((e=>"sentry-trace"===e)):e.headers.split("\r\n").some((e=>e.startsWith("sentry-trace:"))),i||(e.addHeader("sentry-trace",t),n&&e.addHeader("baggage",n))}(t,l?(0,me.Qh)(l):(0,he.TC)(e,n,s),(0,qn.De)(a||(l?(0,ge.k)(l):(0,ge.l)(e,i,o))))}}}__init5(){this._onRequestEnd=e=>{if(!(0,nn.z)([c.KU,"call",e=>e(),"optionalAccess",e=>e.getIntegration,"call",e=>e(Ni)]))return;const{request:t,response:n}=e,i=t.origin?t.origin.toString()+t.path:t.path;if(Mn(i,(0,c.KU)()))return;const s=t.__sentry_span__;s&&(Ue(s,n.statusCode),s.end()),this._options.breadcrumbs&&(0,c.ZQ)({category:"http",data:{method:t.method,status_code:n.statusCode,url:i},type:"http"},{event:"response",request:t,response:n})}}__init6(){this._onRequestError=e=>{if(!(0,nn.z)([c.KU,"call",e=>e(),"optionalAccess",e=>e.getIntegration,"call",e=>e(Ni)]))return;const{request:t}=e,n=t.origin?t.origin.toString()+t.path:t.path;if(Mn(n,(0,c.KU)()))return;const i=t.__sentry_span__;i&&(i.setStatus("internal_error"),i.end()),this._options.breadcrumbs&&(0,c.ZQ)({category:"http",data:{method:t.method,url:n},level:"error",type:"http"},{event:"error",request:t})}}}Ni.__initStatic();const wi=/^(\S+:\\|\/?)([\s\S]*?)((?:\.{1,2}|[^/\\]+?|)(\.[^./\\]*|))(?:[/\\]*)$/;function Ki(e){const t=e.length>1024?`${e.slice(-1024)}`:e,n=wi.exec(t);return n?n.slice(1):[]}function Fi(...e){let t="",n=!1;for(let i=e.length-1;i>=-1&&!n;i--){const s=i>=0?e[i]:"/";s&&(t=`${s}/${t}`,n="/"===s.charAt(0))}return t=function(e,t){let n=0;for(let t=e.length-1;t>=0;t--){const i=e[t];"."===i?e.splice(t,1):".."===i?(e.splice(t,1),n++):n&&(e.splice(t,1),n--)}if(t)for(;n--;n)e.unshift("..");return e}(t.split("/").filter((e=>!!e)),!n).join("/"),(n?"/":"")+t||"."}function ki(e){let t=0;for(;t=0&&""===e[n];n--);return t>n?[]:e.slice(t,n-t+1)}function _i(e){return e.replace(/^[A-Z]:/,"").replace(/\\/g,"/")}function Ji(e=(process.argv[1]?function(){const e=Ki(process.argv[1]),t=e[0];let n=e[1];return t||n?(n&&(n=n.slice(0,n.length-1)),t+n):"."}():process.cwd()),t="\\"===Sn.sep){const n=t?_i(e):e;return e=>{if(!e)return;const i=t?_i(e):e;let{dir:s,base:o,ext:r}=Sn.posix.parse(i);".js"!==r&&".mjs"!==r&&".cjs"!==r||(o=o.slice(0,-1*r.length)),s||(s=".");const a=s.lastIndexOf("/node_modules");if(a>-1)return`${s.slice(a+14).replace(/\//g,".")}:${o}`;if(s.startsWith(n)){let e=s.slice(n.length+1).replace(/\//g,".");return e&&(e+=":"),e+=o,e}return o}}const zi=[B(),b(),w(),Ct(),Rn(),si(),Si(),Ai(),Vi(),Qn(),pi(),Fn(),yi()];function Ui(e){const t=(0,ne.EU)(),n=(0,nn.z)([t,"access",e=>e.__SENTRY__,"optionalAccess",e=>e.integrations])||[];return[...zi,...n]}function xi(e={}){Bn(),void 0===e.defaultIntegrations&&(e.defaultIntegrations=Ui()),void 0===e.dsn&&process.env.SENTRY_DSN&&(e.dsn=process.env.SENTRY_DSN);const t=process.env.SENTRY_TRACES_SAMPLE_RATE;if(void 0===e.tracesSampleRate&&t){const n=parseFloat(t);isFinite(n)&&(e.tracesSampleRate=n)}if(void 0===e.release){const t=Ei();void 0!==t?e.release=t:e.autoSessionTracking=!1}void 0===e.environment&&process.env.SENTRY_ENVIRONMENT&&(e.environment=process.env.SENTRY_ENVIRONMENT),void 0===e.autoSessionTracking&&void 0!==e.dsn&&(e.autoSessionTracking=!0),void 0===e.instrumenter&&(e.instrumenter="sentry");const n={...e,stackParser:(0,Xt.vk)(e.stackParser||Li),integrations:(0,l.mH)(e),transport:e.transport||In};if(function(e,t){!0===t.debug&&(m.T?p.vF.enable():(0,p.pq)((()=>{console.warn("[Sentry] Cannot initialize SDK with `debug` option using a non-debug bundle.")}))),(0,c.o5)().update(t.initialScope);const n=new e(t);mt(n),function(e){e.init?e.init():e.setupIntegrations&&e.setupIntegrations()}(n)}(e.clientClass||Pt,n),e.autoSessionTracking&&((0,c.J0)(),process.on("beforeExit",(()=>{const e=(0,ne.rm)().getSession();e&&!["exited","crashed"].includes(e.status)&&(0,c.ky)()}))),function(){const e=(process.env.SENTRY_USE_ENVIRONMENT||"").toLowerCase();if(!["false","n","no","off","0"].includes(e)){const e=process.env.SENTRY_TRACE,t=process.env.SENTRY_BAGGAGE,n=(0,he.kM)(e,t);(0,c.o5)().setPropagationContext(n)}}(),e.spotlight){const t=(0,c.KU)();if(t&&t.addIntegration){const n=t.getOptions().integrations;for(const e of n)t.addIntegration(e);t.addIntegration(Yi({sidecarUrl:"string"==typeof e.spotlight?e.spotlight:void 0}))}}}function Ti(e){if(void 0===e)return!1;const t=e&&e.getOptions();return!(!t||void 0===t.autoSessionTracking)&&t.autoSessionTracking}function Ei(e){return process.env.SENTRY_RELEASE?process.env.SENTRY_RELEASE:Yt.OW.SENTRY_RELEASE&&Yt.OW.SENTRY_RELEASE.id?Yt.OW.SENTRY_RELEASE.id:process.env.GITHUB_SHA||process.env.COMMIT_REF||process.env.VERCEL_GIT_COMMIT_SHA||process.env.VERCEL_GITHUB_COMMIT_SHA||process.env.VERCEL_GITLAB_COMMIT_SHA||process.env.VERCEL_BITBUCKET_COMMIT_SHA||process.env.ZEIT_GITHUB_COMMIT_SHA||process.env.ZEIT_GITLAB_COMMIT_SHA||process.env.ZEIT_BITBUCKET_COMMIT_SHA||process.env.CF_PAGES_COMMIT_SHA||e}const Li=(0,Xt.gd)((0,Xt.o)(Ji()));function Qi(e){const t=Sn.resolve(e);if(!Hn.existsSync(t))throw new Error(`Cannot read contents of ${t}. Directory does not exist.`);if(!Hn.statSync(t).isDirectory())throw new Error(`Cannot read contents of ${t}, because it is not a directory.`);const n=e=>Hn.readdirSync(e).reduce(((t,i)=>{const s=Sn.join(e,i);return Hn.statSync(s).isDirectory()?t.concat(n(s)):(t.push(s),t)}),[]);return n(t).map((e=>Sn.relative(t,e)))}var ji=n(1615);function Oi(e){const t=(0,c.KU)();return new ji.M(e).setup(t),Promise.resolve()}function Pi(e={}){return function({path:t,type:n,next:i,rawInput:s}){const o=(0,nn.z)([c.KU,"call",e=>e(),"optionalAccess",e=>e.getOptions,"call",e=>e()]),r=(0,c.o5)().getTransaction();if(r){r.updateName(`trpc/${t}`),r.setAttribute(k,"route"),r.op="rpc.server";const i={procedure_type:n};(void 0!==e.attachRpcInput?e.attachRpcInput:(0,nn.z)([o,"optionalAccess",e=>e.sendDefaultPii]))&&(i.input=(0,X.S8)(s)),r.setContext("trpc",i)}function a(e){e.ok||(0,c.Cp)(e.error,{mechanism:{handled:!1,data:{function:"trpcMiddleware"}}})}let l;try{l=i()}catch(e){throw(0,c.Cp)(e,{mechanism:{handled:!1,data:{function:"trpcMiddleware"}}}),e}return(0,f.Qg)(l)?Promise.resolve(l).then((e=>{a(e)}),(e=>{(0,c.Cp)(e,{mechanism:{handled:!1,data:{function:"trpcMiddleware"}}})})):a(l),l}}function Mi(e,t){return dt(e,{include:t})}function Di(e,t,n={}){return ut(e,t,{include:n})}function qi(){return function(e,t,n){const i=(0,nn.z)([c.KU,"call",e=>e(),"optionalAccess",e=>e.getOptions,"call",e=>e()]);if(!i||"sentry"!==i.instrumenter||"OPTIONS"===(0,nn.z)([e,"access",e=>e.method,"optionalAccess",e=>e.toUpperCase,"call",e=>e()])||"HEAD"===(0,nn.z)([e,"access",e=>e.method,"optionalAccess",e=>e.toUpperCase,"call",e=>e()]))return n();const s=e.headers&&(0,f.Kg)(e.headers["sentry-trace"])?e.headers["sentry-trace"]:void 0,o=(0,nn.z)([e,"access",e=>e.headers,"optionalAccess",e=>e.baggage]);if(!Ze(i))return n();const[r,a]=gt(e,{path:!0,method:!0}),l=ve({sentryTrace:s,baggage:o},(t=>(0,c.nb)({name:r,op:"http.server",origin:"auto.http.node.tracingHandler",...t,data:{[k]:a},metadata:{...t.metadata,request:e}},{request:dt(e)})));(0,c.o5)().setSpan(l),t.__sentry_transaction=l,t.once("finish",(()=>{setImmediate((()=>{!function(e,t){if(e){if(!e.metadata.source||"url"===e.metadata.source){const[n,i]=gt(t,{path:!0,method:!0});e.updateName(n),e.setMetadata({source:i})}e.setAttribute("url",t.originalUrl||t.url),t.baseUrl&&e.setAttribute("baseUrl",t.baseUrl),e.setData("query",bt(t,void 0))}}(l,e),Ue(l,t.statusCode),l.end()}))})),n()}}function $i(e){const t=function(e={}){let t;if("include"in e)t={include:e.include};else{const{ip:n,request:i,transaction:s,user:o}=e;(n||i||s||o)&&(t={include:(0,a.Ce)({ip:n,request:i,transaction:s,user:o})})}return t}(e),n=(0,c.KU)();if(n&&Ti(n)){n.initSessionFlusher();const e=(0,c.o5)();e.getSession()&&e.setSession()}return function(n,i,s){if(e&&e.flushTimeout&&e.flushTimeout>0){const t=i.end;i.end=function(n,i,s){(0,c.bX)(e.flushTimeout).then((()=>{t.call(this,n,i,s)})).then(null,(e=>{$n&&p.vF.error(e),t.call(this,n,i,s)}))}}(0,ne.fx)((()=>{const e=(0,c.o5)();e.setSDKProcessingMetadata({request:n,requestDataOptionsFromExpressHandler:t}),Ti((0,c.KU)())&&e.setRequestSession({status:"ok"}),i.once("finish",(()=>{const e=(0,c.KU)();Ti(e)&&setImmediate((()=>{e&&e._captureRequestSession&&e._captureRequestSession()}))})),s()}))}}function es(e){const t=function(e){const t=e.status||e.statusCode||e.status_code||e.output&&e.output.statusCode;return t?parseInt(t,10):500}(e);return t>=500}function ts(e){return function(t,n,i,s){(e&&e.shouldHandleError||es)(t)?(0,c.v4)((e=>{e.setSDKProcessingMetadata({request:n});const o=i.__sentry_transaction;o&&!Ve()&&e.setSpan(o);const r=(0,c.KU)();if(r&&Ti(r)&&void 0!==r._sessionFlusher){const t=e.getRequestSession();t&&void 0!==t.status&&(t.status="crashed")}const a=(0,c.Cp)(t,{mechanism:{type:"middleware",handled:!1}});i.sentry=a,s(t)})):s(t)}}const ns=Pi;function is(e){return e&&void 0!==e.statusCode}const ss={name:"SentryHapiErrorPlugin",version:Zt.M,register:async function(e){e.events.on("request",((e,t)=>{const n=Fe();var i;(function(e){return e&&void 0!==e.error})(t)&&(i=t.error,(0,c.Cp)(i,{mechanism:{type:"hapi",handled:!1,data:{function:"hapiErrorPlugin"}}})),n&&(n.setStatus("internal_error"),n.end())}))}},os={name:"SentryHapiTracingPlugin",version:Zt.M,register:async function(e){const t=e;t.ext("onPreHandler",((e,t)=>{const n=ve({sentryTrace:e.headers["sentry-trace"]||void 0,baggage:e.headers.baggage||void 0},(t=>(0,c.nb)({...t,op:"hapi.request",name:e.route.path,description:`${e.route.method} ${e.path}`})));return(0,c.o5)().setSpan(n),t.continue})),t.ext("onPreResponse",((e,t)=>{const n=Fe();if(e.response&&is(e.response)&&n){const t=e.response;t.header("sentry-trace",(0,me.Qh)(n));const i=(0,qn.De)((0,ge.k)(n));i&&t.header("baggage",i)}return t.continue})),t.ext("onPostHandler",((e,t)=>{const n=Fe();return n&&(e.response&&is(e.response)&&Ue(n,e.response.statusCode),n.end()),t.continue}))}},rs="Hapi",as=(0,l._C)(((e={})=>{const t=e.server;return{name:rs,setupOnce(){t&&(0,a.GS)(t,"start",(e=>async function(){return await this.register(os),await this.register(ss),e.apply(this)}))}}})),cs=(0,l.F)(rs,as);var ls=n(3903);const gs="undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__;function ds(e){const t=(0,nn.z)([e,"call",e=>e(),"access",e=>e.getClient,"call",e=>e(),"optionalAccess",e=>e.getOptions,"call",e=>e()]);return"sentry"!==((0,nn.z)([t,"optionalAccess",e=>e.instrumenter])||"sentry")}class us{static __initStatic(){this.id="Apollo"}constructor(e={useNestjs:!1}){this.name=us.id,this._useNest=!!e.useNestjs}loadDependency(){return this._useNest?this._module=this._module||(0,ls.Vw)("@nestjs/graphql"):this._module=this._module||(0,ls.Vw)("apollo-server-core"),this._module}setupOnce(e,t){if(ds(t))gs&&p.vF.log("Apollo Integration is skipped because of instrumenter configuration.");else if(this._useNest){const e=this.loadDependency();if(!e)return void(gs&&p.vF.error("Apollo-NestJS Integration was unable to require @nestjs/graphql package."));(0,a.GS)(e.GraphQLFactory.prototype,"mergeWithSchema",(function(e){return function(...n){return(0,a.GS)(this.resolversExplorerService,"explore",(function(e){return function(){return bs((0,C.k9)(e.call(this)),t)}})),e.call(this,...n)}}))}else{const e=this.loadDependency();if(!e)return void(gs&&p.vF.error("Apollo Integration was unable to require apollo-server-core package."));(0,a.GS)(e.ApolloServerBase.prototype,"constructSchema",(function(e){return function(){if(!this.config.resolvers)return gs&&(this.config.schema?(p.vF.warn("Apollo integration is not able to trace `ApolloServer` instances constructed via `schema` property.If you are using NestJS with Apollo, please use `Sentry.Integrations.Apollo({ useNestjs: true })` instead."),p.vF.warn()):this.config.modules&&p.vF.warn("Apollo integration is not able to trace `ApolloServer` instances constructed via `modules` property."),p.vF.error("Skipping tracing as no resolvers found on the `ApolloServer` instance.")),e.call(this);const n=(0,C.k9)(this.config.resolvers);return this.config.resolvers=bs(n,t),e.call(this)}}))}}}function bs(e,t){return e.map((e=>(Object.keys(e).forEach((n=>{Object.keys(e[n]).forEach((i=>{"function"==typeof e[n][i]&&function(e,t,n,i){(0,a.GS)(e[t],n,(function(e){return function(...s){const o=i().getScope().getSpan(),r=(0,nn.z)([o,"optionalAccess",e=>e.startChild,"call",e=>e({description:`${t}.${n}`,op:"graphql.resolve",origin:"auto.graphql.apollo"})]),a=e.call(this,...s);return(0,f.Qg)(a)?a.then((e=>((0,nn.z)([r,"optionalAccess",e=>e.end,"call",e=>e()]),e))):((0,nn.z)([r,"optionalAccess",e=>e.end,"call",e=>e()]),a)}}))}(e,n,i,t)}))})),e)))}us.__initStatic();class Is{static __initStatic(){this.id="Express"}constructor(e={}){this.name=Is.id,this._router=e.router||e.app,this._methods=(Array.isArray(e.methods)?e.methods:[]).concat("use")}setupOnce(e,t){this._router?ds(t)?gs&&p.vF.log("Express Integration is skipped because of instrumenter configuration."):(function(e,t=[]){t.forEach((t=>function(e,t){const n=e[t];return e[t]=function(...e){return n.call(this,...function(e,t){return e.map((e=>"function"==typeof e?ps(e,t):Array.isArray(e)?e.map((e=>"function"==typeof e?ps(e,t):e)):e))}(e,t))},e}(e,t)))}(this._router,this._methods),function(e){const t="settings"in e;t&&void 0===e._router&&e.lazyrouter&&e.lazyrouter();const n=t?e._router:e;if(!n)return gs&&p.vF.debug("Cannot instrument router for URL Parameterization (did not find a valid router)."),void(gs&&p.vF.debug("Routing instrumentation is currently only supported in Express 4."));const i=Object.getPrototypeOf(n),s=i.process_params;i.process_params=function(e,t,n,i,o){n._reconstructedRoute||(n._reconstructedRoute="");const{layerRoutePath:r,isRegex:a,isArray:c,numExtraSegments:l}=function(e){let t=(0,nn.z)([e,"access",e=>e.route,"optionalAccess",e=>e.path]);const n=(0,f.gd)(t),i=Array.isArray(t);if(!t){const[n]=Yt.OW.process.versions.node.split(".").map(Number);n>=16&&(t=Cs(e.path,e.regexp,e.keys))}if(!t)return{isRegex:n,isArray:i,numExtraSegments:0};const s=i?Math.max(t.reduce(((e,t)=>e+ot(t.toString())),0)-ot(e.path||""),0):0,o=function(e,t){return e?t.map((e=>e.toString())).join(","):t&&t.toString()}(i,t);return{layerRoutePath:o,isRegex:n,isArray:i,numExtraSegments:s}}(e);let g;(r||a||c)&&(n._hasParameters=!0),g=r||function(e,t,n){const i=st(e||""),s=(0,nn.z)([i,"optionalAccess",e=>e.split,"call",e=>e("/"),"access",e=>e.filter,"call",e=>e((e=>!!e))]);let o=0;const r=(0,nn.z)([t,"optionalAccess",e=>e.split,"call",e=>e("/"),"access",e=>e.filter,"call",e=>e((e=>!!e)),"access",e=>e.length])||0;return(0,nn.z)([n,"optionalAccess",e=>e.split,"call",e=>e("/"),"access",e=>e.filter,"call",e=>e((e=>(0,nn.z)([s,"optionalAccess",e=>e[r+o]])===e&&(o+=1,!0))),"access",e=>e.join,"call",e=>e("/")])}(n.originalUrl,n._reconstructedRoute,e.path)||"";const d=g.split("/").filter((e=>e.length>0&&(a||c||!e.includes("*")))).join("/");if(d&&d.length>0&&(n._reconstructedRoute+=`/${d}${a?"/":""}`),ot(st(n.originalUrl||""))+l===ot(n._reconstructedRoute)){n._hasParameters||n._reconstructedRoute!==n.originalUrl&&(n._reconstructedRoute=n.originalUrl?st(n.originalUrl):n.originalUrl);const e=i.__sentry_transaction,t=e&&(0,me.et)(e).data||{};if(e&&"custom"!==t[k]){const t=n._reconstructedRoute||"/",[i,s]=gt(n,{path:!0,method:!0,customRoute:t});e.updateName(i),e.setAttribute(k,s)}}return s.call(this,e,t,n,i,o)}}(this._router)):gs&&p.vF.error("ExpressIntegration is missing an Express instance")}}function ps(e,t){const n=e.length;switch(n){case 2:return function(n,i){const s=i.__sentry_transaction;if(s){const n=s.startChild({description:e.name,op:`middleware.express.${t}`,origin:"auto.middleware.express"});i.once("finish",(()=>{n.end()}))}return e.call(this,n,i)};case 3:return function(n,i,s){const o=i.__sentry_transaction,r=(0,nn.z)([o,"optionalAccess",e=>e.startChild,"call",n=>n({description:e.name,op:`middleware.express.${t}`,origin:"auto.middleware.express"})]);e.call(this,n,i,(function(...e){(0,nn.z)([r,"optionalAccess",e=>e.end,"call",e=>e()]),s.call(this,...e)}))};case 4:return function(n,i,s,o){const r=s.__sentry_transaction,a=(0,nn.z)([r,"optionalAccess",e=>e.startChild,"call",n=>n({description:e.name,op:`middleware.express.${t}`,origin:"auto.middleware.express"})]);e.call(this,n,i,s,(function(...e){(0,nn.z)([a,"optionalAccess",e=>e.end,"call",e=>e()]),o.call(this,...e)}))};default:throw new Error(`Express middleware takes 2-4 arguments. Got: ${n}`)}}Is.__initStatic();const Cs=(e,t,n)=>{if(!(e&&t&&n&&0!==Object.keys(n).length&&(0,nn.z)([n,"access",e=>e[0],"optionalAccess",e=>e.offset])))return;const i=n.sort(((e,t)=>e.offset-t.offset)),s=new RegExp(t,`${t.flags}d`).exec(e);if(!s||!s.indices)return;const[,...o]=s.indices;if(o.length!==i.length)return;let r=e,a=0;return o.forEach(((e,t)=>{if(e){const[n,s]=e,o=r.substring(0,n-a),c=`:${i[t].name}`,l=r.substring(s-a);r=o+c+l,a+=s-n-c.length}})),r};class hs{static __initStatic(){this.id="GraphQL"}constructor(){this.name=hs.id}loadDependency(){return this._module=this._module||(0,ls.Vw)("graphql/execution/execute.js")}setupOnce(e,t){if(ds(t))return void(gs&&p.vF.log("GraphQL Integration is skipped because of instrumenter configuration."));const n=this.loadDependency();n?(0,a.GS)(n,"execute",(function(e){return function(...n){const i=t().getScope(),s=i.getSpan(),o=(0,nn.z)([s,"optionalAccess",e=>e.startChild,"call",e=>e({description:"execute",op:"graphql.execute",origin:"auto.graphql.graphql"})]);(0,nn.z)([i,"optionalAccess",e=>e.setSpan,"call",e=>e(o)]);const r=e.call(this,...n);return(0,f.Qg)(r)?r.then((e=>((0,nn.z)([o,"optionalAccess",e=>e.end,"call",e=>e()]),(0,nn.z)([i,"optionalAccess",e=>e.setSpan,"call",e=>e(s)]),e))):((0,nn.z)([o,"optionalAccess",e=>e.end,"call",e=>e()]),(0,nn.z)([i,"optionalAccess",e=>e.setSpan,"call",e=>e(s)]),r)}})):gs&&p.vF.error("GraphQL Integration was unable to require graphql/execution package.")}}hs.__initStatic();const ms=["aggregate","bulkWrite","countDocuments","createIndex","createIndexes","deleteMany","deleteOne","distinct","drop","dropIndex","dropIndexes","estimatedDocumentCount","find","findOne","findOneAndDelete","findOneAndReplace","findOneAndUpdate","indexes","indexExists","indexInformation","initializeOrderedBulkOp","insertMany","insertOne","isCapped","mapReduce","options","parallelCollectionScan","rename","replaceOne","stats","updateMany","updateOne"],ys={bulkWrite:["operations"],countDocuments:["query"],createIndex:["fieldOrSpec"],createIndexes:["indexSpecs"],deleteMany:["filter"],deleteOne:["filter"],distinct:["key","query"],dropIndex:["indexName"],find:["query"],findOne:["query"],findOneAndDelete:["filter"],findOneAndReplace:["filter","replacement"],findOneAndUpdate:["filter","update"],indexExists:["indexes"],insertMany:["docs"],insertOne:["doc"],mapReduce:["map","reduce"],rename:["newName"],replaceOne:["filter","doc"],updateMany:["filter","update"],updateOne:["filter","update"]};class Zs{static __initStatic(){this.id="Mongo"}constructor(e={}){this.name=Zs.id,this._operations=Array.isArray(e.operations)?e.operations:ms,this._describeOperations=!("describeOperations"in e)||e.describeOperations,this._useMongoose=!!e.useMongoose}loadDependency(){const e=this._useMongoose?"mongoose":"mongodb";return this._module=this._module||(0,ls.Vw)(e)}setupOnce(e,t){if(ds(t))return void(gs&&p.vF.log("Mongo Integration is skipped because of instrumenter configuration."));const n=this.loadDependency();if(n)this._instrumentOperations(n.Collection,this._operations,t);else{const e=this._useMongoose?"mongoose":"mongodb";gs&&p.vF.error(`Mongo Integration was unable to require \`${e}\` package.`)}}_instrumentOperations(e,t,n){t.forEach((t=>this._patchOperation(e,t,n)))}_patchOperation(e,t,n){if(!(t in e.prototype))return;const i=this._getSpanContextFromOperationArguments.bind(this);(0,a.GS)(e.prototype,t,(function(e){return function(...s){const o=s[s.length-1],r=n(),a=r.getScope(),c=r.getClient(),l=a.getSpan(),g=(0,nn.z)([c,"optionalAccess",e=>e.getOptions,"call",e=>e(),"access",e=>e.sendDefaultPii]);if("function"!=typeof o||"mapReduce"===t&&2===s.length){const n=(0,nn.z)([l,"optionalAccess",e=>e.startChild,"call",e=>e(i(this,t,s,g))]),o=e.call(this,...s);if((0,f.Qg)(o))return o.then((e=>((0,nn.z)([n,"optionalAccess",e=>e.end,"call",e=>e()]),e)));if((d=o)&&"object"==typeof d&&d.once&&"function"==typeof d.once){const e=o;try{e.once("close",(()=>{(0,nn.z)([n,"optionalAccess",e=>e.end,"call",e=>e()])}))}catch(e){(0,nn.z)([n,"optionalAccess",e=>e.end,"call",e=>e()])}return e}return(0,nn.z)([n,"optionalAccess",e=>e.end,"call",e=>e()]),o}var d;const u=(0,nn.z)([l,"optionalAccess",e=>e.startChild,"call",e=>e(i(this,t,s.slice(0,-1)))]);return e.call(this,...s.slice(0,-1),(function(e,t){(0,nn.z)([u,"optionalAccess",e=>e.end,"call",e=>e()]),o(e,t)}))}}))}_getSpanContextFromOperationArguments(e,t,n,i=!1){const s={"db.system":"mongodb","db.name":e.dbName,"db.operation":t,"db.mongodb.collection":e.collectionName},o={op:"db",origin:"auto.db.mongo",description:t,data:s},r=ys[t],a=Array.isArray(this._describeOperations)?this._describeOperations.includes(t):this._describeOperations;if(!r||!a||!i)return o;try{if("mapReduce"===t){const[e,t]=n;s[r[0]]="string"==typeof e?e:e.name||"",s[r[1]]="string"==typeof t?t:t.name||""}else for(let e=0;e(i||(i=t.config),e.apply(t,n))})}catch(e){gs&&p.vF.error("Mysql Integration was unable to instrument `mysql` config.")}function s(e){if(!e)return;const t=i?{"server.address":i.host,"server.port":i.port,"db.user":i.user}:{};Object.keys(t).forEach((n=>{e.setAttribute(n,t[n])})),e.end()}(0,a.GS)(n,"createQuery",(function(e){return function(n,i,o){const r=t().getScope().getSpan(),a=(0,nn.z)([r,"optionalAccess",e=>e.startChild,"call",e=>e({description:"string"==typeof n?n:n.sql,op:"db",origin:"auto.db.mysql",data:{"db.system":"mysql"}})]);if("function"==typeof o)return e.call(this,n,i,(function(e,t,n){s(a),o(e,t,n)}));if("function"==typeof i)return e.call(this,n,(function(e,t,n){s(a),i(e,t,n)}));const c=e.call(this,n,i);return c.on("end",(()=>{s(a)})),c}}))}}Gs.__initStatic();class Bs{static __initStatic(){this.id="Postgres"}constructor(e={}){this.name=Bs.id,this._usePgNative=!!e.usePgNative,this._module=e.module}loadDependency(){return this._module=this._module||(0,ls.Vw)("pg")}setupOnce(e,t){if(ds(t))return void(gs&&p.vF.log("Postgres Integration is skipped because of instrumenter configuration."));const n=this.loadDependency();if(!n)return void(gs&&p.vF.error("Postgres Integration was unable to require `pg` package."));const i=this._usePgNative?(0,nn.z)([n,"access",e=>e.native,"optionalAccess",e=>e.Client]):n.Client;i?(0,a.GS)(i.prototype,"query",(function(e){return function(n,i,s){const o=t().getScope().getSpan(),r={"db.system":"postgresql"};try{this.database&&(r["db.name"]=this.database),this.host&&(r["server.address"]=this.host),this.port&&(r["server.port"]=this.port),this.user&&(r["db.user"]=this.user)}catch(e){}const a=(0,nn.z)([o,"optionalAccess",e=>e.startChild,"call",e=>e({description:"string"==typeof n?n:n.text,op:"db",origin:"auto.db.postgres",data:r})]);if("function"==typeof s)return e.call(this,n,i,(function(e,t){(0,nn.z)([a,"optionalAccess",e=>e.end,"call",e=>e()]),s(e,t)}));if("function"==typeof i)return e.call(this,n,(function(e,t){(0,nn.z)([a,"optionalAccess",e=>e.end,"call",e=>e()]),i(e,t)}));const c=void 0!==i?e.call(this,n,i):e.call(this,n);return(0,f.Qg)(c)?c.then((e=>((0,nn.z)([a,"optionalAccess",e=>e.end,"call",e=>e()]),e))):((0,nn.z)([a,"optionalAccess",e=>e.end,"call",e=>e()]),c)}})):gs&&p.vF.error("Postgres Integration was unable to access 'pg-native' bindings.")}}Bs.__initStatic();class As{static __initStatic(){this.id="Prisma"}constructor(e={}){if(this.name=As.id,(t=e.client)&&t.$use&&!e.client._sentryInstrumented){(0,a.my)(e.client,"_sentryInstrumented",!0);const t={};try{const n=e.client._engineConfig;if(n){const{activeProvider:e,clientVersion:i}=n;e&&(t["db.system"]=e),i&&(t["db.prisma.version"]=i)}}catch(e){}e.client.$use(((e,n)=>{if(ds(ne.BF))return n(e);const i=e.action,s=e.model;return Be({name:s?`${s} ${i}`:i,onlyIfParent:!0,op:"db.prisma",attributes:{[z]:"auto.db.prisma"},data:{...t,"db.operation":i}},(()=>n(e)))}))}else gs&&p.vF.warn("Unsupported Prisma client provided to PrismaIntegration. Provided client:",e.client);var t}setupOnce(){}}As.__initStatic();const Ws="CaptureConsole",fs=(0,l._C)(((e={})=>{const t=e.levels||p.Ow;return{name:Ws,setupOnce(){},setup(e){"console"in Yt.OW&&An((({args:n,level:i})=>{(0,c.KU)()===e&&t.includes(i)&&function(e,t){const n={level:Vn(t),extra:{arguments:e}};(0,c.v4)((i=>{if(i.addEventProcessor((e=>(e.logger="console",(0,C.M6)(e,{handled:!1,type:"console"}),e))),"assert"===t&&!1===e[0]){const t=`Assertion failed: ${(0,h.gt)(e.slice(1)," ")||"console.assert"}`;return i.setExtra("arguments",e.slice(1)),void(0,c.wd)(t,n)}const s=e.find((e=>e instanceof Error));if("error"===t&&s)return void(0,c.Cp)(s,n);const o=(0,h.gt)(e," ");(0,c.wd)(o,n)}))}(n,i)}))}}}));(0,l.F)(Ws,fs);const Vs="Debug",vs=(0,l._C)(((e={})=>{const t={debugger:!1,stringify:!1,...e};return{name:Vs,setupOnce(){},setup(e){e.on&&e.on("beforeSendEvent",((e,n)=>{t.debugger,(0,p.pq)((()=>{t.stringify?(console.log(JSON.stringify(e,null,2)),n&&Object.keys(n).length&&console.log(JSON.stringify(n,null,2))):(console.log(e),n&&Object.keys(n).length&&console.log(n))}))}))}}})),Rs=((0,l.F)(Vs,vs),"undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__),Ys="Dedupe",Xs=(0,l._C)((()=>{let e;return{name:Ys,setupOnce(){},processEvent(t){if(t.type)return t;try{if(function(e,t){return!!t&&(!!function(e,t){const n=e.message,i=t.message;return!(!n&&!i)&&(!(n&&!i||!n&&i)&&(n===i&&(!!Ss(e,t)&&!!Hs(e,t))))}(e,t)||!!function(e,t){const n=Ns(t),i=Ns(e);return!(!n||!i)&&(n.type===i.type&&n.value===i.value&&(!!Ss(e,t)&&!!Hs(e,t)))}(e,t))}(t,e))return Rs&&p.vF.warn("Event dropped due to being a duplicate of previously captured event."),null}catch(e){}return e=t}}}));function Hs(e,t){let n=ws(e),i=ws(t);if(!n&&!i)return!0;if(n&&!i||!n&&i)return!1;if(i.length!==n.length)return!1;for(let e=0;e{const t=e.depth||3,n=e.captureErrorCause||!1;return{name:Ks,setupOnce(){},processEvent:(e,i)=>function(e,t={},n,i){if(!t.originalException||!(0,f.bJ)(t.originalException))return e;const s=t.originalException.name||t.originalException.constructor.name,o=function(e,t){try{const n=["name","message","stack","line","column","fileName","lineNumber","columnNumber","toJSON"],i={};for(const t of Object.keys(e)){if(-1!==n.indexOf(t))continue;const s=e[t];i[t]=(0,f.bJ)(s)?s.toString():s}if(t&&void 0!==e.cause&&(i.cause=(0,f.bJ)(e.cause)?e.cause.toString():e.cause),"function"==typeof e.toJSON){const t=e.toJSON();for(const e of Object.keys(t)){const n=t[e];i[e]=(0,f.bJ)(n)?n.toString():n}}return i}catch(e){Rs&&p.vF.error("Unable to extract extra data from the Error object:",e)}return null}(t.originalException,i);if(o){const t={...e.contexts},i=(0,X.S8)(o,n);return(0,f.Qd)(i)&&((0,a.my)(i,"__sentry_skip_normalization__",!0),t[s]=i),{...e,contexts:t}}return e}(e,i,t,n)}}));(0,l.F)(Ks,Fs);const ks=(0,Yt.VZ)();function _s(e){return e&&/^function fetch\(\)\s+\{\s+\[native code\]\s+\}$/.test(e.toString())}function Js(){if("string"==typeof EdgeRuntime)return!0;if(!function(){if(!("fetch"in ks))return!1;try{return new Headers,new Request("http://www.example.com"),new Response,!0}catch(e){return!1}}())return!1;if(_s(ks.fetch))return!0;let e=!1;const t=ks.document;if(t&&"function"==typeof t.createElement)try{const n=t.createElement("iframe");n.hidden=!0,t.head.appendChild(n),n.contentWindow&&n.contentWindow.fetch&&(e=_s(n.contentWindow.fetch)),t.head.removeChild(n)}catch(e){U.T&&p.vF.warn("Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ",e)}return e}function zs(){Js()&&(0,a.GS)(Yt.OW,"fetch",(function(e){return function(...t){const{method:n,url:i}=function(e){if(0===e.length)return{method:"GET",url:""};if(2===e.length){const[t,n]=e;return{url:xs(t),method:Us(n,"method")?String(n.method).toUpperCase():"GET"}}const t=e[0];return{url:xs(t),method:Us(t,"method")?String(t.method).toUpperCase():"GET"}}(t),s={args:t,fetchData:{method:n,url:i},startTimestamp:Date.now()};return Kt("fetch",{...s}),e.apply(Yt.OW,t).then((e=>(Kt("fetch",{...s,endTimestamp:Date.now(),response:e}),e)),(e=>{throw Kt("fetch",{...s,endTimestamp:Date.now(),error:e}),e}))}}))}function Us(e,t){return!!e&&"object"==typeof e&&!!e[t]}function xs(e){return"string"==typeof e?e:e?Us(e,"url")?e.url:e.toString?e.toString():"":""}const Ts=Yt.OW,Es="__sentry_xhr_v3__";function Ls(){if(!Ts.XMLHttpRequest)return;const e=XMLHttpRequest.prototype;(0,a.GS)(e,"open",(function(e){return function(...t){const n=Date.now(),i=(0,f.Kg)(t[0])?t[0].toUpperCase():void 0,s=function(e){if((0,f.Kg)(e))return e;try{return e.toString()}catch(e){}}(t[1]);if(!i||!s)return e.apply(this,t);this[Es]={method:i,url:s,request_headers:{}},"POST"===i&&s.match(/sentry_key/)&&(this.__sentry_own_request__=!0);const o=()=>{const e=this[Es];if(e&&4===this.readyState){try{e.status_code=this.status}catch(e){}Kt("xhr",{args:[i,s],endTimestamp:Date.now(),startTimestamp:n,xhr:this})}};return"onreadystatechange"in this&&"function"==typeof this.onreadystatechange?(0,a.GS)(this,"onreadystatechange",(function(e){return function(...t){return o(),e.apply(this,t)}})):this.addEventListener("readystatechange",o),(0,a.GS)(this,"setRequestHeader",(function(e){return function(...t){const[n,i]=t,s=this[Es];return s&&(0,f.Kg)(n)&&(0,f.Kg)(i)&&(s.request_headers[n.toLowerCase()]=i),e.apply(this,t)}})),e.apply(this,t)}})),(0,a.GS)(e,"send",(function(e){return function(...t){const n=this[Es];return n?(void 0!==t[0]&&(n.body=t[0]),Kt("xhr",{args:[n.method,n.url],startTimestamp:Date.now(),xhr:this}),e.apply(this,t)):e.apply(this,t)}}))}const Qs="HttpClient",js=(0,l._C)(((e={})=>{const t={failedRequestStatusCodes:[[500,599]],failedRequestTargets:[/.*/],...e};return{name:Qs,setupOnce(){},setup(e){!function(e,t){Js()&&function(){const n="fetch";Nt(n,(n=>{if((0,c.KU)()!==e)return;const{response:i,args:s}=n,[o,r]=s;i&&function(e,t,n,i){if(Ms(e,n.status,n.url)){const e=function(e,t){return!t&&e instanceof Request||e instanceof Request&&e.bodyUsed?e:new Request(e,t)}(t,i);let s,o,r,a;qs()&&([{headers:s,cookies:r},{headers:o,cookies:a}]=[{cookieHeader:"Cookie",obj:e},{cookieHeader:"Set-Cookie",obj:n}].map((({cookieHeader:e,obj:t})=>{const n=function(e){const t={};return e.forEach(((e,n)=>{t[n]=e})),t}(t.headers);let i;try{const t=n[e]||n[e.toLowerCase()]||void 0;t&&(i=Ps(t))}catch(t){Rs&&p.vF.log(`Could not extract cookies from header ${e}`)}return{headers:n,cookies:i}})));const l=Ds({url:e.url,method:e.method,status:n.status,requestHeaders:s,responseHeaders:o,requestCookies:r,responseCookies:a});(0,c.r)(l)}}(t,o,i,r)})),wt(n,zs)}()}(e,t),function(e,t){var n;"XMLHttpRequest"in Yt.OW&&(n=n=>{if((0,c.KU)()!==e)return;const i=n.xhr,s=i[Es];if(!s)return;const{method:o,request_headers:r}=s;try{!function(e,t,n,i){if(Ms(e,t.status,t.responseURL)){let e,s,o;if(qs()){try{const e=t.getResponseHeader("Set-Cookie")||t.getResponseHeader("set-cookie")||void 0;e&&(s=Ps(e))}catch(e){Rs&&p.vF.log("Could not extract cookies from response headers")}try{o=function(e){const t=e.getAllResponseHeaders();return t?t.split("\r\n").reduce(((e,t)=>{const[n,i]=t.split(": ");return e[n]=i,e}),{}):{}}(t)}catch(e){Rs&&p.vF.log("Could not extract headers from response")}e=i}const r=Ds({url:t.responseURL,method:n,status:t.status,requestHeaders:e,responseHeaders:o,responseCookies:s});(0,c.r)(r)}}(t,i,o,r)}catch(e){Rs&&p.vF.warn("Error while extracting response event form XHR response",e)}},Nt("xhr",n),wt("xhr",Ls))}(e,t)}}}));function Os(e){if(e){const t=e["Content-Length"]||e["content-length"];if(t)return parseInt(t,10)}}function Ps(e){return e.split("; ").reduce(((e,t)=>{const[n,i]=t.split("=");return e[n]=i,e}),{})}function Ms(e,t,n){return function(e,t){return e.some((e=>"number"==typeof e?e===t:t>=e[0]&&t<=e[1]))}(e.failedRequestStatusCodes,t)&&(i=e.failedRequestTargets,s=n,i.some((e=>"string"==typeof e?s.includes(e):e.test(s))))&&!Mn(n,(0,c.KU)());var i,s}function Ds(e){const t=`HTTP Client Error with status code: ${e.status}`,n={message:t,exception:{values:[{type:"Error",value:t}]},request:{url:e.url,method:e.method,headers:e.requestHeaders,cookies:e.requestCookies},contexts:{response:{status_code:e.status,headers:e.responseHeaders,cookies:e.responseCookies,body_size:Os(e.responseHeaders)}}};return(0,C.M6)(n,{type:"http.client",handled:!1}),n}function qs(){const e=(0,c.KU)();return!!e&&Boolean(e.getOptions().sendDefaultPii)}(0,l.F)(Qs,js);const $s=Yt.OW,eo="ReportingObserver",to=new WeakMap,no=(0,l._C)(((e={})=>{const t=e.types||["crash","deprecation","intervention"];function n(e){if(to.has((0,c.KU)()))for(const t of e)(0,c.v4)((e=>{e.setExtra("url",t.url);const n=`ReportingObserver [${t.type}]`;let i="No details available";if(t.body){const n={};for(const e in t.body)n[e]=t.body[e];if(e.setExtra("body",n),"crash"===t.type){const e=t.body;i=[e.crashId||"",e.reason||""].join(" ").trim()||i}else i=t.body.message||i}(0,c.wd)(`${n}: ${i}`)}))}return{name:eo,setupOnce(){"ReportingObserver"in ks&&new $s.ReportingObserver(n,{buffered:!0,types:t}).observe()},setup(e){to.set(e,!0)}}})),io=((0,l.F)(eo,no),"RewriteFrames"),so=(0,l._C)(((e={})=>{const t=e.root,n=e.prefix||"app:///",i=e.iteratee||(e=>{if(!e.filename)return e;const i=/^[a-zA-Z]:\\/.test(e.filename)||e.filename.includes("\\")&&!e.filename.includes("/"),s=/^\//.test(e.filename);if(i||s){const s=i?e.filename.replace(/^[a-zA-Z]:/,"").replace(/\\/g,"/"):e.filename,o=t?function(e,t){e=Fi(e).slice(1),t=Fi(t).slice(1);const n=ki(e.split("/")),i=ki(t.split("/")),s=Math.min(n.length,i.length);let o=s;for(let e=0;ei(e)))}}return{name:io,setupOnce(){},processEvent(e){let t=e;return e.exception&&Array.isArray(e.exception.values)&&(t=function(e){try{return{...e,exception:{...e.exception,values:e.exception.values.map((e=>({...e,...e.stacktrace&&{stacktrace:s(e.stacktrace)}})))}}}catch(t){return e}}(t)),t}}})),oo=((0,l.F)(io,so),"SessionTiming"),ro=(0,l._C)((()=>{const e=Date.now();return{name:oo,setupOnce(){},processEvent(t){const n=Date.now();return{...t,extra:{...t.extra,"session:start":e,"session:duration":n-e,"session:end":n}}}}})),ao=((0,l.F)(oo,ro),[["january","1"],["february","2"],["march","3"],["april","4"],["may","5"],["june","6"],["july","7"],["august","8"],["september","9"],["october","10"],["november","11"],["december","12"],["jan","1"],["feb","2"],["mar","3"],["apr","4"],["may","5"],["jun","6"],["jul","7"],["aug","8"],["sep","9"],["oct","10"],["nov","11"],["dec","12"],["sunday","0"],["monday","1"],["tuesday","2"],["wednesday","3"],["thursday","4"],["friday","5"],["saturday","6"],["sun","0"],["mon","1"],["tue","2"],["wed","3"],["thu","4"],["fri","5"],["sat","6"]]);function co(e){return ao.reduce(((e,[t,n])=>e.replace(new RegExp(t,"gi"),n)),e)}const lo="Automatic instrumentation of CronJob only supports crontab string",go=Ji(),uo={...F,...o,...r},bo={instrumentCron:function(e,t){let n=!1;return new Proxy(e,{construct(e,i){const[s,o,r,a,l,...g]=i;if("string"!=typeof s)throw new Error(lo);if(n)throw new Error(`A job named '${t}' has already been scheduled`);n=!0;const d=co(s);return new e(s,(function(e,n){return(0,c.T$)(t,(()=>o(e,n)),{schedule:{type:"crontab",value:d},timezone:l||void 0})}),r,a,l,...g)},get:(e,i)=>"from"===i?i=>{const{cronTime:s,onTick:o,timeZone:r}=i;if("string"!=typeof s)throw new Error(lo);if(n)throw new Error(`A job named '${t}' has already been scheduled`);n=!0;const a=co(s);return i.onTick=(e,n)=>(0,c.T$)(t,(()=>o(e,n)),{schedule:{type:"crontab",value:a},timezone:r||void 0}),e.from(i)}:e[i]})},instrumentNodeCron:function(e){return new Proxy(e,{get:(e,t)=>"schedule"===t&&e.schedule?new Proxy(e.schedule,{apply(e,t,n){const[i,,s]=n;if(!(0,nn.z)([s,"optionalAccess",e=>e.name]))throw new Error('Missing "name" for scheduled job. A name is required for Sentry check-in monitoring.');return(0,c.T$)(s.name,(()=>e.apply(t,n)),{schedule:{type:"crontab",value:co(i)},timezone:(0,nn.z)([s,"optionalAccess",e=>e.timezone])})}}):e[t]})},instrumentNodeSchedule:function(e){return new Proxy(e,{get:(e,t)=>"scheduleJob"===t?new Proxy(e.scheduleJob,{apply(e,t,n){const[i,s]=n;if("string"!=typeof i||"string"!=typeof s)throw new Error("Automatic instrumentation of 'node-schedule' requires the first parameter of 'scheduleJob' to be a job name string and the second parameter to be a crontab string");const o=i,r=s;return(0,c.T$)(o,(()=>e.apply(t,n)),{schedule:{type:"crontab",value:co(r)}})}}):e[t]})}}},1615:(e,t,n)=>{"use strict";n.d(t,{M:()=>m,a:()=>h});var i=n(853);function s(e){const t=(0,i.z)(e);return null==t||t}var o=n(7016),r=n(2486),a=n(1535),c=n(6641),l=n(3741),g=n(5836),d=n(7412),u=n(6341),b=n(3903),I=n(3245);function p(e,...t){d.vF.log(`[ANR] ${e}`,...t)}function C(){const e=(0,r.m6)().getScopeData();return(0,a.Rg)(e,(0,c.rm)().getScopeData()),(0,a.Rg)(e,(0,l.o5)().getScopeData()),e.attachments=[],e.eventProcessors=[],e}e=n.hmd(e);const h=(0,g._C)(((t={})=>{if(I.S.major<16||16===I.S.major&&I.S.minor<17)throw new Error("ANR detection requires Node 16.17.0 or later");let r,a;return u.OW.__SENTRY_GET_SCOPES__=C,{name:"Anr",setupOnce(){},startWorker:()=>{r||a&&(r=async function(t,r){const a=t.getDsn();if(!a)return()=>{};const c=await async function(e){let t={message:"ANR"};const n={};for(const i of e.getEventProcessors()){if(null===t)break;t=await i(t,n)}return(0,i.z)([t,"optionalAccess",e=>e.contexts])||{}}(t);s([c,"access",e=>e.app,"optionalAccess",e=>delete e.app_memory]),s([c,"access",e=>e.device,"optionalAccess",e=>delete e.free_memory]);const g=t.getOptions(),u=t.getSdkMetadata()||{};u.sdk&&(u.sdk.integrations=g.integrations.map((e=>e.name)));const I={debug:d.vF.isEnabled(),dsn:a,environment:g.environment||"production",release:g.release,dist:g.dist,sdkMetadata:u,appRootPath:r.appRootPath,pollInterval:r.pollInterval||50,anrThreshold:r.anrThreshold||5e3,captureStackTrace:!!r.captureStackTrace,staticTags:r.staticTags||{},contexts:c};if(I.captureStackTrace){const e=n(264);e.url()||e.open(0)}const{Worker:C}=(0,b.fj)(e,"worker_threads"),h=new C(new o.URL("data:application/javascript;base64,aW1wb3J0IHsgU2Vzc2lvbiB9IGZyb20gJ2luc3BlY3Rvcic7CmltcG9ydCB7IHdvcmtlckRhdGEsIHBhcmVudFBvcnQgfSBmcm9tICd3b3JrZXJfdGhyZWFkcyc7CmltcG9ydCB7IHBvc2l4LCBzZXAgfSBmcm9tICdwYXRoJzsKaW1wb3J0ICogYXMgaHR0cCBmcm9tICdodHRwJzsKaW1wb3J0ICogYXMg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BTeW5jUHJvbWlzZSgocmVzb2x2ZSwgcmVqZWN0KSA9PiB7CiAgICAgIHRoaXMuX2hhbmRsZXJzLnB1c2goWwogICAgICAgIGZhbHNlLAogICAgICAgIHJlc3VsdCA9PiB7CiAgICAgICAgICBpZiAoIW9uZnVsZmlsbGVkKSB7CiAgICAgICAgICAgIC8vIFRPRE86IMKvXF8o44OEKV8vwq8KICAgICAgICAgICAgLy8gVE9ETzogRklYTUUKICAgICAgICAgICAgcmVzb2x2ZShyZXN1bHQgKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgcmVzb2x2ZShvbmZ1bGZpbGxlZChyZXN1bHQpKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIHJlamVjdChlKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgcmVhc29uID0+IHsKICAgICAgICAgIGlmICghb25yZWplY3RlZCkgewogICAgICAgICAgICByZWplY3QocmVhc29uKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgcmVzb2x2ZShvbnJlamVjdGVkKHJlYXNvbikpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgcmVqZWN0KGUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgXSk7CiAgICAgIHRoaXMuX2V4ZWN1dGVIYW5kbGVycygpOwogICAgfSk7CiAgfQoKICAvKiogSlNEb2MgKi8KICAgY2F0Y2goCiAgICBvbnJlamVjdGVkLAogICkgewogICAgcmV0dXJuIHRoaXMudGhlbih2YWwgPT4gdmFsLCBvbnJlamVjdGVkKTsKICB9CgogIC8qKiBKU0RvYyAqLwogICBmaW5hbGx5KG9uZmluYWxseSkgewogICAgcmV0dXJuIG5ldyBTeW5jUHJvbWlzZSgocmVzb2x2ZSwgcmVqZWN0KSA9PiB7CiAgICAgIGxldCB2YWw7CiAgICAgIGxldCBpc1JlamVjdGVkOwoKICAgICAgcmV0dXJuIHRoaXMudGhlbigKICAgICAgICB2YWx1ZSA9PiB7CiAgICAgICAgICBpc1JlamVjdGVkID0gZmFsc2U7CiAgICAgICAgICB2YWwgPSB2YWx1ZTsKICAgICAgICAgIGlmIChvbmZpbmFsbHkpIHsKICAgICAgICAgICAgb25maW5hbGx5KCk7CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICByZWFzb24gPT4gewogICAgICAgICAgaXNSZWplY3RlZCA9IHRydWU7CiAgICAgICAgICB2YWwgPSByZWFzb247CiAgICAgICAgICBpZiAob25maW5hbGx5KSB7CiAgICAgICAgICAgIG9uZmluYWxseSgpOwogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICkudGhlbigoKSA9PiB7CiAgICAgICAgaWYgKGlzUmVqZWN0ZWQpIHsKICAgICAgICAgIHJlamVjdCh2YWwpOwogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KCiAgICAgICAgcmVzb2x2ZSh2YWwgKTsKICAgICAgfSk7CiAgICB9KTsKICB9CgogIC8qKiBKU0RvYyAqLwogICAgX19pbml0KCkge3RoaXMuX3Jlc29sdmUgPSAodmFsdWUpID0+IHsKICAgIHRoaXMuX3NldFJlc3VsdChTdGF0ZXMuUkVTT0xWRUQsIHZhbHVlKTsKICB9O30KCiAgLyoqIEpTRG9jICovCiAgICBfX2luaXQyKCkge3RoaXMuX3JlamVjdCA9IChyZWFzb24pID0+IHsKICAgIHRoaXMuX3NldFJlc3VsdChTdGF0ZXMuUkVKRUNURUQsIHJlYXNvbik7CiAgfTt9CgogIC8qKiBKU0RvYyAqLwogICAgX19pbml0MygpIHt0aGlzLl9zZXRSZXN1bHQgPSAoc3RhdGUsIHZhbHVlKSA9PiB7CiAgICBpZiAodGhpcy5fc3RhdGUgIT09IFN0YXRlcy5QRU5ESU5HKSB7CiAgICAgIHJldHVybjsKICAgIH0KCiAgICBpZiA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25vdGlmeVNjb3BlTGlzdGVuZXJzKCk7CiAgICByZXR1cm4gdGhpczsKICB9CgogIC8qKgogICAqIEBpbmhlcml0RG9jCiAgICovCiAgIHNldFRhZyhrZXksIHZhbHVlKSB7CiAgICB0aGlzLl90YWdzID0geyAuLi50aGlzLl90YWdzLCBba2V5XTogdmFsdWUgfTsKICAgIHRoaXMuX25vdGlmeVNjb3BlTGlzdGVuZXJzKCk7CiAgICByZXR1cm4gdGhpczsKICB9CgogIC8qKgogICAqIEBpbmhlcml0RG9jCiAgICovCiAgIHNldEV4dHJhcyhleHRyYXMpIHsKICAgIHRoaXMuX2V4dHJhID0gewogICAgICAuLi50aGlzLl9leHRyYSwKICAgICAgLi4uZXh0cmFzLAogICAgfTsKICAgIHRoaXMuX25vdGlmeVNjb3BlTGlzdGVuZXJzKCk7CiAgICByZXR1cm4gdGhpczsKICB9CgogIC8qKgogICAqIEBpbmhlcml0RG9jCiAgICovCiAgIHNldEV4dHJhKGtleSwgZXh0cmEpIHsKICAgIHRoaXMuX2V4dHJhID0geyAuLi50aGlzLl9leHRyYSwgW2tleV06IGV4dHJhIH07CiAgICB0aGlzLl9ub3RpZnlTY29wZUxpc3RlbmVycygpOwogICAgcmV0dXJuIHRoaXM7CiAgfQoKICAvKioKICAgKiBAaW5oZXJpdERvYwogICAqLwogICBzZXRGaW5nZXJwcmludChmaW5nZXJwcmludCkgewogICAgdGhpcy5fZmluZ2VycHJpbnQgPSBmaW5nZXJwcmludDsKICAgIHRoaXMuX25vdGlmeVNjb3BlTGlzdGVuZXJzKCk7CiAgICByZXR1cm4gdGhpczsKICB9CgogIC8qKgogICAqIEBpbmhlcml0RG9jCiAgICovCiAgIHNldExldmVsKAogICAgLy8gZXNsaW50LWRpc2FibGUtbmV4dC1saW5lIGRlcHJlY2F0aW9uL2RlcHJlY2F0aW9uCiAgICBsZXZlbCwKICApIHsKICAgIHRoaXMuX2xldmVsID0gbGV2ZWw7CiAgICB0aGlzLl9ub3RpZnlTY29wZU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pdERvYwogICAqLwogICBjbGVhckJyZWFkY3J1bWJzKCkgewogICAgdGhpcy5fYnJlYWRjcnVtYnMgPSBbXTsKICAgIHRoaXMuX25vdGlmeVNjb3BlTGlzdGVuZXJzKCk7CiAgICByZXR1cm4gdGhpczsKICB9CgogIC8qKgogICAqIEBpbmhlcml0RG9jCiAgICovCiAgIGFkZEF0dGFjaG1lbnQoYXR0YWNobWVudCkgewogICAgdGhpcy5fYXR0YWNobWVudHMucHVzaChhdHRhY2htZW50KTsKICAgIHJldHVybiB0aGlzOwogIH0KCiAgLyoqCiAgICogQGluaGVyaXREb2MKICAgKiBAZGVwcmVjYXRlZCBVc2UgYGdldFNjb3BlRGF0YSgpYCBpbnN0ZWFkLgogICAqLwogICBnZXRBdHRhY2htZW50cygpIHsKICAgIGNvbnN0IGRhdGEgPSB0aGlzLmdldFNjb3BlRGF0YSgpOwoKICAgIHJldHVybiBkYXRhLmF0dGFjaG1lbnRzOwogIH0KCiAgLyoqCiAgICogQGluaGVyaXREb2MKICAgKi8KICAgY2xlYXJBdHRhY2htZW50cygpIHsKICAgIHRoaXMuX2F0dGFjaG1lbnRzID0gW107CiAgICByZXR1cm4gdGhpczsKICB9CgogIC8qKiBAaW5oZXJpdERvYyAqLwogICBnZXRTY29wZURhdGEoKSB7CiAgICBjb25zdCB7CiAgICAgIF9icmVhZGNydW1icywKICAgICAgX2F0dGFjaG1lbnRzLAogICAgICBfY29udGV4dHMsCiAgICAgIF90YWdzLAogICAgICBfZXh0cmEsCiAgICAgIF91c2VyLAogICAgICBfbGV2ZWwsCiAgICAgIF9maW5nZXJwcmludCwKICAgICAgX2V2ZW50UHJvY2Vzc29ycywKICAgICAgX3Byb3BhZ2F0aW9uQ29udGV4dCwKICAgICAgX3Nka1Byb2Nlc3NpbmdNZXRhZGF0YSwKICAgICAgX3RyYW5zYWN0aW9uTmFtZSwKICAgICAgX3NwYW4sCiAgICB9ID0gdGhpczsKCiAgICByZXR1cm4gewogICAgICBicmVhZGNydW1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bnRyeS5zZXRDdXJyZW50Q2xpZW50KGNsaWVudCk7CiAgICogICAgY2xpZW50LmluaXQoKTsKICAgKiB9KTsKICAgKiBgYGAKICAgKgogICAqIElmIHlvdSBhcmUgdXNpbmcgdGhlIEh1YiB0byBjYXB0dXJlIGV2ZW50cyBsaWtlIHNvOgogICAqCiAgICogYGBgCiAgICogLy8gT0xECiAgICogY29uc3QgY2xpZW50ID0gbmV3IENsaWVudCgpOwogICAqIGNvbnN0IGh1YiA9IG5ldyBIdWIoY2xpZW50KTsKICAgKiBodWIuY2FwdHVyZUV4Y2VwdGlvbigpCiAgICogYGBgCiAgICoKICAgKiBpbnN0ZWFkIGNhcHR1cmUgaXNvbGF0ZWQgZXZlbnRzIGFzIGZvbGxvd3M6CiAgICoKICAgKiBgYGAKICAgKiAvLyBORVcKICAgKiBjb25zdCBjbGllbnQgPSBuZXcgQ2xpZW50KCk7CiAgICogY29uc3Qgc2NvcGUgPSBuZXcgU2NvcGUoKTsKICAgKiBzY29wZS5zZXRDbGllbnQoY2xpZW50KTsKICAgKiBzY29wZS5jYXB0dXJlRXhjZXB0aW9uKCk7CiAgICogYGBgCiAgICovCiAgIGNvbnN0cnVjdG9yKAogICAgY2xpZW50LAogICAgc2NvcGUsCiAgICBpc29sYXRpb25TY29wZSwKICAgICAgX3ZlcnNpb24gPSBBUElfVkVSU0lPTiwKICApIHt0aGlzLl92ZXJzaW9uID0gX3ZlcnNpb247CiAgICBsZXQgYXNzaWduZWRTY29wZTsKICAgIGlmICghc2NvcGUpIHsKICAgICAgYXNzaWduZWRTY29wZSA9IG5ldyBTY29wZSgpOwogICAgICBhc3NpZ25lZFNjb3BlLnNldENsaWVudChjbGllbnQpOwogICAgfSBlbHNlIHsKICAgICAgYXNzaWduZWRTY29wZSA9IHNjb3BlOwogICAgfQoKICAgIGxldCBhc3NpZ25lZElzb2xhdGlvblNjb3BlOwogICAgaWYgKCFpc29sYXRpb25TY29wZSkgewogICAgICBhc3NpZ25lZElzb2xhdG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XJyb3IgLSBpc1RoZW5hYmxlIHJldHVybnMgdGhlIHdyb25nIHR5cGUKICAgICAgcmV0dXJuIG1heWJlUHJvbWlzZVJlc3VsdC50aGVuKAogICAgICAgIHJlcyA9PiB7CiAgICAgICAgICAvLyBlc2xpbnQtZGlzYWJsZS1uZXh0LWxpbmUgZGVwcmVjYXRpb24vZGVwcmVjYXRpb24KICAgICAgICAgIHRoaXMucG9wU2NvcGUoKTsKICAgICAgICAgIHJldHVybiByZXM7CiAgICAgICAgfSwKICAgICAgICBlID0+IHsKICAgICAgICAgIC8vIGVzbGludC1kaXNhYmxlLW5leHQtbGluZSBkZXByZWNhdGlvbi9kZXByZWNhdGlvbgogICAgICAgICAgdGhpcy5wb3BTY29wZSgpOwogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9LAogICAgICApOwogICAgfQoKICAgIC8vIGVzbGludC1kaXNhYmxlLW5leHQtbGluZSBkZXByZWNhdGlvbi9kZXByZWNhdGlvbgogICAgdGhpcy5wb3BTY29wZSgpOwogICAgcmV0dXJuIG1heWJlUHJvbWlzZVJlc3VsdDsKICB9CgogIC8qKgogICAqIEBpbmhlcml0RG9jCiAgICoKICAgKiBAZGVwcmVjYXRlZCBVc2UgYFNlbnRyeS5nZXRDbGllbnQoKWAgaW5zdGVhZC4KICAgKi8KICAgZ2V0Q2xpZW50KCkgewogICAgLy8gZXNsaW50LWRpc2FibGUtbmV4dC1saW5lIGRlcHJlY2F0aW9uL2RlcHJlY2F0aW9uCiAgICByZXR1cm4gdGhpcy5nZXRTdGFja1RvcCgpLmNsaWVudCA7CiAgfQoKICAvKioKICAgKiBSZXR1cm5zIHRoZSBzY29wZSBvZiB0aGUgdG9wIHN0YWNrLgogICAqCiAgICogQGRlcHJlY2F0ZWQgVXNlIGBTZW50cnkuZ2V0Q3VycmVudFNjb3BlKClgIGluc3RlYWQuCiAgICovCiAgIGdldFNjb3BlKCkgewogICAgLy8gZXNsaW50LWRpc2FibGUtbmV4dC1saW5lIGRlcH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AgewogICAgICAgICAgbWV0aG9kOiAnUE9TVCcsCiAgICAgICAgICBhZ2VudCwKICAgICAgICAgIGhlYWRlcnMsCiAgICAgICAgICBob3N0bmFtZSwKICAgICAgICAgIHBhdGg6IGAke3BhdGhuYW1lfSR7c2VhcmNofWAsCiAgICAgICAgICBwb3J0LAogICAgICAgICAgcHJvdG9jb2wsCiAgICAgICAgICBjYTogb3B0aW9ucy5jYUNlcnRzLAogICAgICAgIH0sCiAgICAgICAgcmVzID0+IHsKICAgICAgICAgIHJlcy5vbignZGF0YScsICgpID0+IHsKICAgICAgICAgICAgLy8gRHJhaW4gc29ja2V0CiAgICAgICAgICB9KTsKCiAgICAgICAgICByZXMub24oJ2VuZCcsICgpID0+IHsKICAgICAgICAgICAgLy8gRHJhaW4gc29ja2V0CiAgICAgICAgICB9KTsKCiAgICAgICAgICByZXMuc2V0RW5jb2RpbmcoJ3V0ZjgnKTsKCiAgICAgICAgICAvLyAiS2V5LXZhbHVlIHBhaXJzIG9mIGhlYWRlciBuYW1lcyBhbmQgdmFsdWVzLiBIZWFkZXIgbmFtZXMgYXJlIGxvd2VyLWNhc2VkLiIKICAgICAgICAgIC8vIGh0dHBzOi8vbm9kZWpzLm9yZy9hcGkvaHR0cC5odG1sI2h0dHBfbWVzc2FnZV9oZWFkZXJzCiAgICAgICAgICBjb25zdCByZXRyeUFmdGVySGVhZGVyID0gX251bGxpc2hDb2FsZXNjZShyZXMuaGVhZGVyc1sncmV0cnktYWZ0ZXInXSwgKCkgPT4gKCBudWxsKSk7CiAgICAgICAgICBjb25zdCByYXRlTGltaXRzSGVhZGVyID0gX251bGxpc2hDb2FsZXNjZShyZXMuaGVhZGVyc1sneC1zZW50cnktcmF0ZS1saW1pdHMnXSwgKCkgPT4gKCBudWxsKSk7CgogICAgICAgICAgcmVzb2x2ZSh7CiAgICAgICAgICAgIHN0YXR1c0NvZGU6IHJlcy5zdGF0dXNDb2RlLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICA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zICsgbmFub1NlY29uZHMgLyAxZTYpOwogICAgfSwKICAgIHJlc2V0OiAoKSA9PiB7CiAgICAgIGxhc3RQb2xsID0gcHJvY2Vzcy5ocnRpbWUoKTsKICAgIH0sCiAgfTsKfQoKZnVuY3Rpb24gd2F0Y2hkb2dUaW1lb3V0KCkgewogIGxvZygnV2F0Y2hkb2cgdGltZW91dCcpOwoKICBpZiAoZGVidWdnZXJQYXVzZSkgewogICAgbG9nKCdQYXVzaW5nIGRlYnVnZ2VyIHRvIGNhcHR1cmUgc3RhY2sgdHJhY2UnKTsKICAgIGRlYnVnZ2VyUGF1c2UoKTsKICB9IGVsc2UgewogICAgbG9nKCdDYXB0dXJpbmcgZXZlbnQgd2l0aG91dCBhIHN0YWNrIHRyYWNlJyk7CiAgICBzZW5kQW5yRXZlbnQoKS50aGVuKG51bGwsICgpID0+IHsKICAgICAgbG9nKCdTZW5kaW5nIEFOUiBldmVudCBmYWlsZWQgb24gd2F0Y2hkb2cgdGltZW91dC4nKTsKICAgIH0pOwogIH0KfQoKY29uc3QgeyBwb2xsIH0gPSB3YXRjaGRvZ1RpbWVyKGNyZWF0ZUhyVGltZXIsIG9wdGlvbnMucG9sbEludGVydmFsLCBvcHRpb25zLmFuclRocmVzaG9sZCwgd2F0Y2hkb2dUaW1lb3V0KTsKCl9vcHRpb25hbENoYWluKFtwYXJlbnRQb3J0LCAnb3B0aW9uYWxBY2Nlc3MnLCBfNiA9PiBfNi5vbiwgJ2NhbGwnLCBfNyA9PiBfNygnbWVzc2FnZScsIChtc2cpID0+IHsKICBpZiAobXNnLnNlc3Npb24pIHsKICAgIHNlc3Npb24gPSBtYWtlU2Vzc2lvbihtc2cuc2Vzc2lvbik7CiAgfQoKICBwb2xsKCk7Cn0pXSk7"),{workerData:I});process.on("exit",(()=>{h.terminate()}));const m=setInterval((()=>{try{const e=(0,l.o5)().getSession(),t=e?{...e,toJSON:void 0}:void 0;h.postMessage({session:t})}catch(e){}}),I.pollInterval);return m.unref(),h.on("message",(e=>{"session-ended"===e&&(p("ANR event sent from ANR worker. Clearing session in this thread."),(0,l.o5)().setSession(void 0))})),h.once("error",(e=>{clearInterval(m),p("ANR worker error",e)})),h.once("exit",(e=>{clearInterval(m),p("ANR worker exit",e)})),h.unref(),()=>{h.terminate(),clearInterval(m)}}(a,t))},stopWorker:()=>{r&&r.then((e=>{e(),r=void 0}))},setup(e){a=e,setImmediate((()=>this.startWorker()))}}})),m=(0,g.F)("Anr",h)},3245:(e,t,n)=>{"use strict";n.d(t,{S:()=>i});const i=(0,n(6936).kf)(process.versions.node)},2786:(e,t,n)=>{"use strict";n.d(t,{j:()=>s});var i=n(3903);e=n.hmd(e);const s=[()=>new((0,i.fj)(e,"./apollo").Apollo),()=>new((0,i.fj)(e,"./apollo").Apollo)({useNestjs:!0}),()=>new((0,i.fj)(e,"./graphql").GraphQL),()=>new((0,i.fj)(e,"./mongo").Mongo),()=>new((0,i.fj)(e,"./mongo").Mongo)({mongoose:!0}),()=>new((0,i.fj)(e,"./mysql").Mysql),()=>new((0,i.fj)(e,"./postgres").Postgres)]},5664:(e,t,n)=>{"use strict";n.r(t),n.d(t,{BROWSER_TRACING_INTEGRATION_ID:()=>Wt,BrowserTracing:()=>ht,IdleTransaction:()=>Yt,Integrations:()=>Nt,Span:()=>At,SpanStatus:()=>St,TRACEPARENT_REGEXP:()=>Rt,Transaction:()=>Bt,addExtensionMethods:()=>mt,defaultRequestInstrumentationOptions:()=>ft,extractTraceparentData:()=>Zt,getActiveTransaction:()=>yt,hasTracingEnabled:()=>Vt,instrumentOutgoingRequests:()=>Xt,spanStatusfromHttpCode:()=>Gt,startIdleTransaction:()=>Ht,stripUrlQueryAndFragment:()=>vt});var i=n(683),s=n(1763),o=n(1692),r=n(5071),a=n(9071),c=n(6202),l=n(1206),g=n(138),d=n(2231);const u=(0,d.VZ)();function b(e,t={}){if(!e)return"";try{let n=e;const i=5,s=[];let o=0,r=0;const a=" > ",c=a.length;let l;const g=Array.isArray(t)?t:t.keyAttrs,d=!Array.isArray(t)&&t.maxStringLength||80;for(;n&&o++1&&r+s.length*c+l.length>=d));)s.push(l),r+=l.length,n=n.parentNode;return s.reverse().join(a)}catch(e){return""}}function I(e,t){const n=e,i=[];let s,o,r,a,c;if(!n||!n.tagName)return"";if(u.HTMLElement&&n instanceof HTMLElement&&n.dataset&&n.dataset.sentryComponent)return n.dataset.sentryComponent;i.push(n.tagName.toLowerCase());const l=t&&t.length?t.filter((e=>n.getAttribute(e))).map((e=>[e,n.getAttribute(e)])):null;if(l&&l.length)l.forEach((e=>{i.push(`[${e[0]}="${e[1]}"]`)}));else if(n.id&&i.push(`#${n.id}`),s=n.className,s&&(0,g.Kg)(s))for(o=s.split(/\s+/),c=0;c{let i,s;return o=>{t.value>=0&&(o||n)&&(s=t.value-(i||0),(s||void 0===i)&&(i=t.value,t.delta=s,e(t)))}},G=()=>m.__WEB_VITALS_POLYFILL__?m.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||(()=>{const e=m.performance.timing,t=m.performance.navigation.type,n={entryType:"navigation",startTime:0,type:2==t?"back_forward":1===t?"reload":"navigate"};for(const t in e)"navigationStart"!==t&&"toJSON"!==t&&(n[t]=Math.max(e[t]-e.navigationStart,0));return n})()):m.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0],B=()=>{const e=G();return e&&e.activationStart||0},A=(e,t)=>{const n=G();let i="navigate";return n&&(i=m.document&&m.document.prerendering||B()>0?"prerender":n.type.replace(/_/g,"-")),{name:e,value:void 0===t?-1:t,rating:"good",delta:0,entries:[],id:`v3-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:i}},W=(e,t,n)=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){const i=new PerformanceObserver((e=>{t(e.getEntries())}));return i.observe(Object.assign({type:e,buffered:!0},n||{})),i}}catch(e){}},f=(e,t)=>{const n=i=>{"pagehide"!==i.type&&"hidden"!==m.document.visibilityState||(e(i),t&&(removeEventListener("visibilitychange",n,!0),removeEventListener("pagehide",n,!0)))};m.document&&(addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0))};let V=-1;const v=()=>(V<0&&(m.document&&m.document.visibilityState&&(V="hidden"!==m.document.visibilityState||m.document.prerendering?1/0:0),f((({timeStamp:e})=>{V=e}),!0)),{get firstHiddenTime(){return V}});let R=0,Y=1/0,X=0;const H=e=>{e.forEach((e=>{e.interactionId&&(Y=Math.min(Y,e.interactionId),X=Math.max(X,e.interactionId),R=X?(X-Y)/7+1:0)}))};let S;const N=()=>{"interactionCount"in performance||S||(S=W("event",H,{type:"event",buffered:!0,durationThreshold:0}))},w=()=>S?R:performance.interactionCount||0,K=[],F={},k=e=>{const t=K[K.length-1],n=F[e.interactionId];if(n||K.length<10||e.duration>t.latency){if(n)n.entries.push(e),n.latency=Math.max(n.latency,e.duration);else{const t={id:e.interactionId,latency:e.duration,entries:[e]};F[t.id]=t,K.push(t)}K.sort(((e,t)=>t.latency-e.latency)),K.splice(10).forEach((e=>{delete F[e.id]}))}},_={},J=e=>{m.document&&(m.document.prerendering?addEventListener("prerenderingchange",(()=>J(e)),!0):"complete"!==m.document.readyState?addEventListener("load",(()=>J(e)),!0):setTimeout(e,0))},z={},U={};let x,T,E,L,Q;function j(e,t){return te(e,t),U[e]||(function(e){const t={};"event"===e&&(t.durationThreshold=0),W(e,(t=>{O(e,{entries:t})}),t)}(e),U[e]=!0),ne(e,t)}function O(e,t){const n=z[e];if(n&&n.length)for(const i of n)try{i(t)}catch(t){C&&c.vF.error(`Error while triggering instrumentation handler.\nType: ${e}\nName: ${(0,y.qQ)(i)}\nError:`,t)}}function P(){return((e,t={})=>{const n=A("CLS",0);let i,s=0,o=[];const r=e=>{e.forEach((e=>{if(!e.hadRecentInput){const t=o[0],r=o[o.length-1];s&&0!==o.length&&e.startTime-r.startTime<1e3&&e.startTime-t.startTime<5e3?(s+=e.value,o.push(e)):(s=e.value,o=[e]),s>n.value&&(n.value=s,n.entries=o,i&&i())}}))},a=W("layout-shift",r);if(a){i=Z(e,n,t.reportAllChanges);const s=()=>{r(a.takeRecords()),i(!0)};return f(s),s}})((e=>{O("cls",{metric:e}),x=e}),{reportAllChanges:!0})}function M(){return(()=>{const e=v(),t=A("FID");let n;const i=i=>{i.startTime{e.forEach(i)},o=W("first-input",s);n=Z((e=>{O("fid",{metric:e}),T=e}),t),o&&f((()=>{s(o.takeRecords()),o.disconnect()}),!0)})()}function D(){return(()=>{const e=v(),t=A("LCP");let n;const i=i=>{const s=i[i.length-1];if(s){const i=Math.max(s.startTime-B(),0);i{O("lcp",{metric:e}),E=e}),t);const e=()=>{_[t.id]||(i(s.takeRecords()),s.disconnect(),_[t.id]=!0,n(!0))};return["keydown","click"].forEach((t=>{m.document&&addEventListener(t,e,{once:!0,capture:!0})})),f(e,!0),e}})()}function q(){return((e,t)=>{t=t||{};const n=A("TTFB"),i=Z((e=>{O("ttfb",{metric:e}),L=e}),n,t.reportAllChanges);J((()=>{const e=G();if(e){if(n.value=Math.max(e.responseStart-B(),0),n.value<0||n.value>performance.now())return;n.entries=[e],i(!0)}}))})()}function $(){return((e,t)=>{t=t||{},N();const n=A("INP");let i;const s=e=>{e.forEach((e=>{e.interactionId&&k(e),"first-input"===e.entryType&&!K.some((t=>t.entries.some((t=>e.duration===t.duration&&e.startTime===t.startTime))))&&k(e)}));const t=(()=>{const e=Math.min(K.length-1,Math.floor(w()/50));return K[e]})();t&&t.latency!==n.value&&(n.value=t.latency,n.entries=t.entries,i())},o=W("event",s,{durationThreshold:t.durationThreshold||40});i=Z(e,n,t.reportAllChanges),o&&(o.observe({type:"first-input",buffered:!0}),f((()=>{s(o.takeRecords()),n.value<0&&w()>0&&(n.value=0,n.entries=[]),i(!0)})))})((e=>{O("inp",{metric:e}),Q=e}))}function ee(e,t,n,i,s=!1){let o;return te(e,t),U[e]||(o=n(),U[e]=!0),i&&t({metric:i}),ne(e,t,s?o:void 0)}function te(e,t){z[e]=z[e]||[],z[e].push(t)}function ne(e,t,n){return()=>{n&&n();const i=z[e];if(!i)return;const s=i.indexOf(t);-1!==s&&i.splice(s,1)}}var ie=n(7037);function se(e){return[{type:"span"},e]}var oe=n(5177),re=n(6056),ae=n(7567);function ce(e){if(!e)return{};const t=e.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)return{};const n=t[6]||"",i=t[8]||"";return{host:t[4],path:t[5],protocol:t[2],search:n,hash:i,relative:t[5]+n+i}}function le(e){return e.split(/[\?#]/,1)[0]}function ge(e){return e.split(/\\?\//).filter((e=>e.length>0&&","!==e)).length}function de(e){return"number"==typeof e&&isFinite(e)}function ue(e,{startTimestamp:t,...n}){return t&&e.startTimestamp>t&&(e.startTimestamp=t),e.startChild({startTimestamp:t,...n})}function be(e){return e/1e3}function Ie(){return m&&m.addEventListener&&m.performance}let pe,Ce,he=0,me={};function ye(){const e=Ie();if(e&&ae.k3){e.mark&&m.performance.mark("sentry-tracing-init");const t=ee("fid",(({metric:e})=>{const t=e.entries[e.entries.length-1];if(!t)return;const n=be(ae.k3),i=be(t.startTime);C&&c.vF.log("[Measurements] Adding FID"),me.fid={value:e.value,unit:"millisecond"},me["mark.fid"]={value:n+i,unit:"second"}}),M,T),n=function(e,t=!1){return ee("cls",e,P,x,t)}((({metric:e})=>{const t=e.entries[e.entries.length-1];t&&(C&&c.vF.log("[Measurements] Adding CLS"),me.cls={value:e.value,unit:""},Ce=t)}),!0),i=function(e,t=!1){return ee("lcp",e,D,E,t)}((({metric:e})=>{const t=e.entries[e.entries.length-1];t&&(C&&c.vF.log("[Measurements] Adding LCP"),me.lcp={value:e.value,unit:"millisecond"},pe=t)}),!0),s=ee("ttfb",(({metric:e})=>{e.entries[e.entries.length-1]&&(C&&c.vF.log("[Measurements] Adding TTFB"),me.ttfb={value:e.value,unit:"millisecond"})}),q,L);return()=>{t(),n(),i(),s()}}return()=>{}}const Ze={click:"click",pointerdown:"click",pointerup:"click",mousedown:"click",mouseup:"click",touchstart:"click",touchend:"click",mouseover:"hover",mouseout:"hover",mouseenter:"hover",mouseleave:"hover",pointerover:"hover",pointerout:"hover",pointerenter:"hover",pointerleave:"hover",dragstart:"drag",dragend:"drag",drag:"drag",dragenter:"drag",dragleave:"drag",dragover:"drag",drop:"drag",keydown:"press",keyup:"press",keypress:"press",input:"press"};function Ge(e,t,n,i,s,o){const r=o?t[o]:t[`${n}End`],a=t[`${n}Start`];a&&r&&ue(e,{op:"browser",origin:"auto.browser.browser.metrics",description:s||n,startTimestamp:i+be(a),endTimestamp:i+be(r)})}function Be(e,t,n,i){const s=t[n];null!=s&&s<2147483647&&(e[i]=s)}var Ae=n(4131),We=n(6588),fe=n(9589),Ve=n(9738),ve=n(1041),Re=n(9610);const Ye=(0,d.VZ)();function Xe(e){return e&&/^function fetch\(\)\s+\{\s+\[native code\]\s+\}$/.test(e.toString())}var He=n(6768);function Se(){(function(){if("string"==typeof EdgeRuntime)return!0;if(!function(){if(!("fetch"in Ye))return!1;try{return new Headers,new Request("http://www.example.com"),new Response,!0}catch(e){return!1}}())return!1;if(Xe(Ye.fetch))return!0;let e=!1;const t=Ye.document;if(t&&"function"==typeof t.createElement)try{const n=t.createElement("iframe");n.hidden=!0,t.head.appendChild(n),n.contentWindow&&n.contentWindow.fetch&&(e=Xe(n.contentWindow.fetch)),t.head.removeChild(n)}catch(e){Re.T&&c.vF.warn("Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ",e)}return e})()&&(0,ve.GS)(d.OW,"fetch",(function(e){return function(...t){const{method:n,url:i}=function(e){if(0===e.length)return{method:"GET",url:""};if(2===e.length){const[t,n]=e;return{url:we(t),method:Ne(n,"method")?String(n.method).toUpperCase():"GET"}}const t=e[0];return{url:we(t),method:Ne(t,"method")?String(t.method).toUpperCase():"GET"}}(t),s={args:t,fetchData:{method:n,url:i},startTimestamp:Date.now()};return(0,He.aj)("fetch",{...s}),e.apply(d.OW,t).then((e=>{const t={...s,endTimestamp:Date.now(),response:e};return(0,He.aj)("fetch",t),e}),(e=>{const t={...s,endTimestamp:Date.now(),error:e};throw(0,He.aj)("fetch",t),e}))}}))}function Ne(e,t){return!!e&&"object"==typeof e&&!!e[t]}function we(e){return"string"==typeof e?e:e?Ne(e,"url")?e.url:e.toString?e.toString():"":""}const Ke=d.OW,Fe="__sentry_xhr_v3__";function ke(){if(!Ke.XMLHttpRequest)return;const e=XMLHttpRequest.prototype;(0,ve.GS)(e,"open",(function(e){return function(...t){const n=Date.now(),i=(0,g.Kg)(t[0])?t[0].toUpperCase():void 0,s=function(e){if((0,g.Kg)(e))return e;try{return e.toString()}catch(e){}}(t[1]);if(!i||!s)return e.apply(this,t);this[Fe]={method:i,url:s,request_headers:{}},"POST"===i&&s.match(/sentry_key/)&&(this.__sentry_own_request__=!0);const o=()=>{const e=this[Fe];if(e&&4===this.readyState){try{e.status_code=this.status}catch(e){}const t={args:[i,s],endTimestamp:Date.now(),startTimestamp:n,xhr:this};(0,He.aj)("xhr",t)}};return"onreadystatechange"in this&&"function"==typeof this.onreadystatechange?(0,ve.GS)(this,"onreadystatechange",(function(e){return function(...t){return o(),e.apply(this,t)}})):this.addEventListener("readystatechange",o),(0,ve.GS)(this,"setRequestHeader",(function(e){return function(...t){const[n,i]=t,s=this[Fe];return s&&(0,g.Kg)(n)&&(0,g.Kg)(i)&&(s.request_headers[n.toLowerCase()]=i),e.apply(this,t)}})),e.apply(this,t)}})),(0,ve.GS)(e,"send",(function(e){return function(...t){const n=this[Fe];if(!n)return e.apply(this,t);void 0!==t[0]&&(n.body=t[0]);const i={args:[n.method,n.url],startTimestamp:Date.now(),xhr:this};return(0,He.aj)("xhr",i),e.apply(this,t)}}))}var _e=n(8562);const Je=["localhost",/^\/(?!\/)/],ze={traceFetch:!0,traceXHR:!0,enableHTTPTimings:!0,tracingOrigins:Je,tracePropagationTargets:Je};function Ue(e){const{traceFetch:t,traceXHR:n,tracePropagationTargets:i,tracingOrigins:s,shouldCreateSpanForRequest:o,enableHTTPTimings:c}={traceFetch:ze.traceFetch,traceXHR:ze.traceXHR,...e},d="function"==typeof o?o:e=>!0,u=e=>function(e,t){return function(e,t=[],n=!1){return t.some((t=>function(e,t,n=!1){return!!(0,g.Kg)(e)&&((0,g.gd)(t)?t.test(e):!!(0,g.Kg)(t)&&(n?e===t:e.includes(t)))}(e,t,n)))}(e,t||Je)}(e,i||s),b={};var I;t&&function(){const e="fetch";(0,He.s5)(e,(e=>{const t=function(e,t,n,i,s="auto.http.browser"){if(!(0,oe.w)()||!e.fetchData)return;const o=t(e.fetchData.url);if(e.endTimestamp&&o){const t=e.fetchData.__span;if(!t)return;const n=i[t];return void(n&&(function(e,t){if(t.response){(0,Ae.N8)(e,t.response.status);const n=t.response&&t.response.headers&&t.response.headers.get("content-length");if(n){const t=parseInt(n);t>0&&e.setAttribute("http.response_content_length",t)}}else t.error&&e.setStatus("internal_error");e.end()}(n,e),delete i[t]))}const c=(0,a.o5)(),d=(0,a.KU)(),{method:u,url:b}=e.fetchData,I=function(e){try{return new URL(e).href}catch(e){return}}(b),p=I?ce(I).host:void 0,C=o?(0,fe.Uk)({name:`${u} ${b}`,onlyIfParent:!0,attributes:{url:b,type:"fetch","http.method":u,"http.url":I,"server.address":p,[r.JD]:s},op:"http.client"}):void 0;if(C&&(e.fetchData.__span=C.spanContext().spanId,i[C.spanContext().spanId]=C),n(e.fetchData.url)&&d){const t=e.args[0];e.args[1]=e.args[1]||{};const n=e.args[1];n.headers=function(e,t,n,i,s){const o=s||n.getSpan(),r=(0,We.rm)(),{traceId:a,spanId:c,sampled:d,dsc:u}={...r.getPropagationContext(),...n.getPropagationContext()},b=o?(0,h.Qh)(o):(0,l.TC)(a,c,d),I=(0,_e.De)(u||(o?(0,Ve.k)(o):(0,Ve.l)(a,t,n))),p=i.headers||("undefined"!=typeof Request&&(0,g.tH)(e,Request)?e.headers:void 0);if(p){if("undefined"!=typeof Headers&&(0,g.tH)(p,Headers)){const e=new Headers(p);return e.append("sentry-trace",b),I&&e.append(_e.hF,I),e}if(Array.isArray(p)){const e=[...p,["sentry-trace",b]];return I&&e.push([_e.hF,I]),e}{const e="baggage"in p?p.baggage:void 0,t=[];return Array.isArray(e)?t.push(...e):e&&t.push(e),I&&t.push(I),{...p,"sentry-trace":b,baggage:t.length>0?t.join(","):void 0}}}return{"sentry-trace":b,baggage:I}}(t,d,c,n,C)}return C}(e,d,u,b);if(t){const n=Ee(e.fetchData.url),i=n?ce(n).host:void 0;t.setAttributes({"http.url":n,"server.address":i})}c&&t&&xe(t)})),(0,He.AS)(e,Se)}(),n&&(I=e=>{const t=function(e,t,n,i){const s=e.xhr,o=s&&s[Fe];if(!(0,oe.w)()||!s||s.__sentry_own_request__||!o)return;const c=t(o.url);if(e.endTimestamp&&c){const e=s.__sentry_xhr_span_id__;if(!e)return;const t=i[e];return void(t&&void 0!==o.status_code&&((0,Ae.N8)(t,o.status_code),t.end(),delete i[e]))}const g=(0,a.o5)(),d=(0,We.rm)(),u=Ee(o.url),b=u?ce(u).host:void 0,I=c?(0,fe.Uk)({name:`${o.method} ${o.url}`,onlyIfParent:!0,attributes:{type:"xhr","http.method":o.method,"http.url":u,url:o.url,"server.address":b,[r.JD]:"auto.http.browser"},op:"http.client"}):void 0;I&&(s.__sentry_xhr_span_id__=I.spanContext().spanId,i[s.__sentry_xhr_span_id__]=I);const p=(0,a.KU)();if(s.setRequestHeader&&n(o.url)&&p){const{traceId:e,spanId:t,sampled:n,dsc:i}={...d.getPropagationContext(),...g.getPropagationContext()};!function(e,t,n){try{e.setRequestHeader("sentry-trace",t),n&&e.setRequestHeader(_e.hF,n)}catch(e){}}(s,I?(0,h.Qh)(I):(0,l.TC)(e,t,n),(0,_e.De)(i||(I?(0,Ve.k)(I):(0,Ve.l)(e,p,g))))}return I}(e,d,u,b);c&&t&&xe(t)},(0,He.s5)("xhr",I),(0,He.AS)("xhr",ke))}function xe(e){const{url:t}=(0,h.et)(e).data||{};if(!t||"string"!=typeof t)return;const n=j("resource",(({entries:i})=>{i.forEach((i=>{(function(e){return"resource"===e.entryType&&"initiatorType"in e&&"string"==typeof e.nextHopProtocol&&("fetch"===e.initiatorType||"xmlhttprequest"===e.initiatorType)})(i)&&i.name.endsWith(t)&&(function(e){const{name:t,version:n}=function(e){let t="unknown",n="unknown",i="";for(const s of e){if("/"===s){[t,n]=e.split("/");break}if(!isNaN(Number(s))){t="h"===i?"http":i,n=e.split(i)[1];break}i+=s}return i===e&&(t=i),{name:t,version:n}}(e.nextHopProtocol),i=[];return i.push(["network.protocol.version",n],["network.protocol.name",t]),ae.k3?[...i,["http.request.redirect_start",Te(e.redirectStart)],["http.request.fetch_start",Te(e.fetchStart)],["http.request.domain_lookup_start",Te(e.domainLookupStart)],["http.request.domain_lookup_end",Te(e.domainLookupEnd)],["http.request.connect_start",Te(e.connectStart)],["http.request.secure_connection_start",Te(e.secureConnectionStart)],["http.request.connection_end",Te(e.connectEnd)],["http.request.request_start",Te(e.requestStart)],["http.request.response_start",Te(e.responseStart)],["http.request.response_end",Te(e.responseEnd)]]:i}(i).forEach((t=>e.setAttribute(...t))),setTimeout(n))}))}))}function Te(e=0){return((ae.k3||performance.timeOrigin)+e)/1e3}function Ee(e){try{return new URL(e,m.location.origin).href}catch(e){return}}const Le=(0,d.VZ)(),Qe=d.OW;let je;function Oe(){if(!function(){const e=Le.chrome,t=e&&e.app&&e.app.runtime,n="history"in Le&&!!Le.history.pushState&&!!Le.history.replaceState;return!t&&n}())return;const e=Qe.onpopstate;function t(e){return function(...t){const n=t.length>2?t[2]:void 0;if(n){const e=je,t=String(n);je=t;const i={from:e,to:t};(0,He.aj)("history",i)}return e.apply(this,t)}}Qe.onpopstate=function(...t){const n=Qe.location.href,i=je;je=n;const s={from:i,to:n};if((0,He.aj)("history",s),e)try{return e.apply(this,t)}catch(e){}},(0,ve.GS)(Qe.history,"pushState",t),(0,ve.GS)(Qe.history,"replaceState",t)}const Pe="BrowserTracing",Me={...i.Cq,markBackgroundTransactions:!0,routingInstrumentation:function(e,t=!0,n=!0){if(!m||!m.location)return void(C&&c.vF.warn("Could not initialize routing instrumentation due to invalid location"));let i,s=m.location.href;t&&(i=e({name:m.location.pathname,startTimestamp:ae.k3?ae.k3/1e3:void 0,op:"pageload",origin:"auto.pageload.browser",metadata:{source:"url"}})),n&&function(){const t="history";(0,He.s5)(t,(({to:t,from:n})=>{void 0===n&&s&&-1!==s.indexOf(t)?s=void 0:n!==t&&(s=void 0,i&&(C&&c.vF.log(`[Tracing] Finishing current transaction with op: ${i.op}`),i.end()),i=e({name:m.location.pathname,op:"navigation",origin:"auto.navigation.browser",metadata:{source:"url"}}))})),(0,He.AS)(t,Oe)}()},startTransactionOnLocationChange:!0,startTransactionOnPageLoad:!0,enableLongTask:!0,enableInp:!1,interactionsSampleRate:1,_experiments:{},...ze};function De(e){const t=(n=`meta[name=${e}]`,u.document&&u.document.querySelector?u.document.querySelector(n):null);var n;return t?t.getAttribute("content"):void 0}function qe(e){const t=e.attributes&&e.attributes[r.i_],n=e.data&&e.data[r.i_],i=e.metadata&&e.metadata.source;return t||n||i}var $e=n(2581),et=n(9049);function tt(e){let t,n=e[0],i=1;for(;in.call(t,...e))),t=void 0)}return n}var nt=n(8560),it=n(4902);function st(e){const t=tt([e,"call",e=>e(),"access",e=>e.getClient,"call",e=>e(),"optionalAccess",e=>e.getOptions,"call",e=>e()]);return"sentry"!==(tt([t,"optionalAccess",e=>e.instrumenter])||"sentry")}class ot{static __initStatic(){this.id="Apollo"}constructor(e={useNestjs:!1}){this.name=ot.id,this._useNest=!!e.useNestjs}loadDependency(){return this._useNest?this._module=this._module||(0,nt.Vw)("@nestjs/graphql"):this._module=this._module||(0,nt.Vw)("apollo-server-core"),this._module}setupOnce(e,t){if(st(t))C&&c.vF.log("Apollo Integration is skipped because of instrumenter configuration.");else if(this._useNest){const e=this.loadDependency();if(!e)return void(C&&c.vF.error("Apollo-NestJS Integration was unable to require @nestjs/graphql package."));(0,ve.GS)(e.GraphQLFactory.prototype,"mergeWithSchema",(function(e){return function(...n){return(0,ve.GS)(this.resolversExplorerService,"explore",(function(e){return function(){return rt((0,it.k9)(e.call(this)),t)}})),e.call(this,...n)}}))}else{const e=this.loadDependency();if(!e)return void(C&&c.vF.error("Apollo Integration was unable to require apollo-server-core package."));(0,ve.GS)(e.ApolloServerBase.prototype,"constructSchema",(function(e){return function(){if(!this.config.resolvers)return C&&(this.config.schema?(c.vF.warn("Apollo integration is not able to trace `ApolloServer` instances constructed via `schema` property.If you are using NestJS with Apollo, please use `Sentry.Integrations.Apollo({ useNestjs: true })` instead."),c.vF.warn()):this.config.modules&&c.vF.warn("Apollo integration is not able to trace `ApolloServer` instances constructed via `modules` property."),c.vF.error("Skipping tracing as no resolvers found on the `ApolloServer` instance.")),e.call(this);const n=(0,it.k9)(this.config.resolvers);return this.config.resolvers=rt(n,t),e.call(this)}}))}}}function rt(e,t){return e.map((e=>(Object.keys(e).forEach((n=>{Object.keys(e[n]).forEach((i=>{"function"==typeof e[n][i]&&function(e,t,n,i){(0,ve.GS)(e[t],n,(function(e){return function(...s){const o=tt([i().getScope().getSpan(),"optionalAccess",e=>e.startChild,"call",e=>e({description:`${t}.${n}`,op:"graphql.resolve",origin:"auto.graphql.apollo"})]),r=e.call(this,...s);return(0,g.Qg)(r)?r.then((e=>(tt([o,"optionalAccess",e=>e.end,"call",e=>e()]),e))):(tt([o,"optionalAccess",e=>e.end,"call",e=>e()]),r)}}))}(e,n,i,t)}))})),e)))}ot.__initStatic();class at{static __initStatic(){this.id="Express"}constructor(e={}){this.name=at.id,this._router=e.router||e.app,this._methods=(Array.isArray(e.methods)?e.methods:[]).concat("use")}setupOnce(e,t){this._router?st(t)?C&&c.vF.log("Express Integration is skipped because of instrumenter configuration."):(function(e,t=[]){t.forEach((t=>function(e,t){const n=e[t];return e[t]=function(...e){return n.call(this,...function(e,t){return e.map((e=>"function"==typeof e?ct(e,t):Array.isArray(e)?e.map((e=>"function"==typeof e?ct(e,t):e)):e))}(e,t))},e}(e,t)))}(this._router,this._methods),function(e){const t="settings"in e;t&&void 0===e._router&&e.lazyrouter&&e.lazyrouter();const n=t?e._router:e;if(!n)return C&&c.vF.debug("Cannot instrument router for URL Parameterization (did not find a valid router)."),void(C&&c.vF.debug("Routing instrumentation is currently only supported in Express 4."));const i=Object.getPrototypeOf(n),s=i.process_params;i.process_params=function(e,t,n,i,o){n._reconstructedRoute||(n._reconstructedRoute="");const{layerRoutePath:a,isRegex:c,isArray:l,numExtraSegments:u}=function(e){let t=tt([e,"access",e=>e.route,"optionalAccess",e=>e.path]);const n=(0,g.gd)(t),i=Array.isArray(t);if(!t){const[n]=d.OW.process.versions.node.split(".").map(Number);n>=16&&(t=lt(e.path,e.regexp,e.keys))}if(!t)return{isRegex:n,isArray:i,numExtraSegments:0};const s=i?Math.max(t.reduce(((e,t)=>e+ge(t.toString())),0)-ge(e.path||""),0):0,o=function(e,t){return e?t.map((e=>e.toString())).join(","):t&&t.toString()}(i,t);return{layerRoutePath:o,isRegex:n,isArray:i,numExtraSegments:s}}(e);let b;(a||c||l)&&(n._hasParameters=!0),b=a||function(e,t,n){const i=tt([le(e||""),"optionalAccess",e=>e.split,"call",e=>e("/"),"access",e=>e.filter,"call",e=>e((e=>!!e))]);let s=0;const o=tt([t,"optionalAccess",e=>e.split,"call",e=>e("/"),"access",e=>e.filter,"call",e=>e((e=>!!e)),"access",e=>e.length])||0;return tt([n,"optionalAccess",e=>e.split,"call",e=>e("/"),"access",e=>e.filter,"call",e=>e((e=>tt([i,"optionalAccess",e=>e[o+s]])===e&&(s+=1,!0))),"access",e=>e.join,"call",e=>e("/")])}(n.originalUrl,n._reconstructedRoute,e.path)||"";const I=b.split("/").filter((e=>e.length>0&&(c||l||!e.includes("*")))).join("/");if(I&&I.length>0&&(n._reconstructedRoute+=`/${I}${c?"/":""}`),ge(le(n.originalUrl||""))+u===ge(n._reconstructedRoute)){n._hasParameters||n._reconstructedRoute!==n.originalUrl&&(n._reconstructedRoute=n.originalUrl?le(n.originalUrl):n.originalUrl);const e=i.__sentry_transaction,t=e&&(0,h.et)(e).data||{};if(e&&"custom"!==t[r.i_]){const t=n._reconstructedRoute||"/",[i,s]=function(e,t={}){const n=e.method&&e.method.toUpperCase();let i="",s="url";t.customRoute||e.route?(i=t.customRoute||`${e.baseUrl||""}${e.route&&e.route.path}`,s="route"):(e.originalUrl||e.url)&&(i=le(e.originalUrl||e.url||""));let o="";return t.method&&n&&(o+=n),t.method&&t.path&&(o+=" "),t.path&&i&&(o+=i),[o,s]}(n,{path:!0,method:!0,customRoute:t});e.updateName(i),e.setAttribute(r.i_,s)}}return s.call(this,e,t,n,i,o)}}(this._router)):C&&c.vF.error("ExpressIntegration is missing an Express instance")}}function ct(e,t){const n=e.length;switch(n){case 2:return function(n,i){const s=i.__sentry_transaction;if(s){const n=s.startChild({description:e.name,op:`middleware.express.${t}`,origin:"auto.middleware.express"});i.once("finish",(()=>{n.end()}))}return e.call(this,n,i)};case 3:return function(n,i,s){const o=tt([i.__sentry_transaction,"optionalAccess",e=>e.startChild,"call",n=>n({description:e.name,op:`middleware.express.${t}`,origin:"auto.middleware.express"})]);e.call(this,n,i,(function(...e){tt([o,"optionalAccess",e=>e.end,"call",e=>e()]),s.call(this,...e)}))};case 4:return function(n,i,s,o){const r=tt([s.__sentry_transaction,"optionalAccess",e=>e.startChild,"call",n=>n({description:e.name,op:`middleware.express.${t}`,origin:"auto.middleware.express"})]);e.call(this,n,i,s,(function(...e){tt([r,"optionalAccess",e=>e.end,"call",e=>e()]),o.call(this,...e)}))};default:throw new Error(`Express middleware takes 2-4 arguments. Got: ${n}`)}}at.__initStatic();const lt=(e,t,n)=>{if(!(e&&t&&n&&0!==Object.keys(n).length&&tt([n,"access",e=>e[0],"optionalAccess",e=>e.offset])))return;const i=n.sort(((e,t)=>e.offset-t.offset)),s=new RegExp(t,`${t.flags}d`).exec(e);if(!s||!s.indices)return;const[,...o]=s.indices;if(o.length!==i.length)return;let r=e,a=0;return o.forEach(((e,t)=>{if(e){const[n,s]=e,o=r.substring(0,n-a),c=`:${i[t].name}`,l=r.substring(s-a);r=o+c+l,a+=s-n-c.length}})),r};class gt{static __initStatic(){this.id="GraphQL"}constructor(){this.name=gt.id}loadDependency(){return this._module=this._module||(0,nt.Vw)("graphql/execution/execute.js")}setupOnce(e,t){if(st(t))return void(C&&c.vF.log("GraphQL Integration is skipped because of instrumenter configuration."));const n=this.loadDependency();n?(0,ve.GS)(n,"execute",(function(e){return function(...n){const i=t().getScope(),s=i.getSpan(),o=tt([s,"optionalAccess",e=>e.startChild,"call",e=>e({description:"execute",op:"graphql.execute",origin:"auto.graphql.graphql"})]);tt([i,"optionalAccess",e=>e.setSpan,"call",e=>e(o)]);const r=e.call(this,...n);return(0,g.Qg)(r)?r.then((e=>(tt([o,"optionalAccess",e=>e.end,"call",e=>e()]),tt([i,"optionalAccess",e=>e.setSpan,"call",e=>e(s)]),e))):(tt([o,"optionalAccess",e=>e.end,"call",e=>e()]),tt([i,"optionalAccess",e=>e.setSpan,"call",e=>e(s)]),r)}})):C&&c.vF.error("GraphQL Integration was unable to require graphql/execution package.")}}gt.__initStatic();const dt=["aggregate","bulkWrite","countDocuments","createIndex","createIndexes","deleteMany","deleteOne","distinct","drop","dropIndex","dropIndexes","estimatedDocumentCount","find","findOne","findOneAndDelete","findOneAndReplace","findOneAndUpdate","indexes","indexExists","indexInformation","initializeOrderedBulkOp","insertMany","insertOne","isCapped","mapReduce","options","parallelCollectionScan","rename","replaceOne","stats","updateMany","updateOne"],ut={bulkWrite:["operations"],countDocuments:["query"],createIndex:["fieldOrSpec"],createIndexes:["indexSpecs"],deleteMany:["filter"],deleteOne:["filter"],distinct:["key","query"],dropIndex:["indexName"],find:["query"],findOne:["query"],findOneAndDelete:["filter"],findOneAndReplace:["filter","replacement"],findOneAndUpdate:["filter","update"],indexExists:["indexes"],insertMany:["docs"],insertOne:["doc"],mapReduce:["map","reduce"],rename:["newName"],replaceOne:["filter","doc"],updateMany:["filter","update"],updateOne:["filter","update"]};class bt{static __initStatic(){this.id="Mongo"}constructor(e={}){this.name=bt.id,this._operations=Array.isArray(e.operations)?e.operations:dt,this._describeOperations=!("describeOperations"in e)||e.describeOperations,this._useMongoose=!!e.useMongoose}loadDependency(){const e=this._useMongoose?"mongoose":"mongodb";return this._module=this._module||(0,nt.Vw)(e)}setupOnce(e,t){if(st(t))return void(C&&c.vF.log("Mongo Integration is skipped because of instrumenter configuration."));const n=this.loadDependency();if(n)this._instrumentOperations(n.Collection,this._operations,t);else{const e=this._useMongoose?"mongoose":"mongodb";C&&c.vF.error(`Mongo Integration was unable to require \`${e}\` package.`)}}_instrumentOperations(e,t,n){t.forEach((t=>this._patchOperation(e,t,n)))}_patchOperation(e,t,n){if(!(t in e.prototype))return;const i=this._getSpanContextFromOperationArguments.bind(this);(0,ve.GS)(e.prototype,t,(function(e){return function(...s){const o=s[s.length-1],r=n(),a=r.getScope(),c=r.getClient(),l=a.getSpan(),d=tt([c,"optionalAccess",e=>e.getOptions,"call",e=>e(),"access",e=>e.sendDefaultPii]);if("function"!=typeof o||"mapReduce"===t&&2===s.length){const n=tt([l,"optionalAccess",e=>e.startChild,"call",e=>e(i(this,t,s,d))]),o=e.call(this,...s);if((0,g.Qg)(o))return o.then((e=>(tt([n,"optionalAccess",e=>e.end,"call",e=>e()]),e)));if((u=o)&&"object"==typeof u&&u.once&&"function"==typeof u.once){const e=o;try{e.once("close",(()=>{tt([n,"optionalAccess",e=>e.end,"call",e=>e()])}))}catch(e){tt([n,"optionalAccess",e=>e.end,"call",e=>e()])}return e}return tt([n,"optionalAccess",e=>e.end,"call",e=>e()]),o}var u;const b=tt([l,"optionalAccess",e=>e.startChild,"call",e=>e(i(this,t,s.slice(0,-1)))]);return e.call(this,...s.slice(0,-1),(function(e,t){tt([b,"optionalAccess",e=>e.end,"call",e=>e()]),o(e,t)}))}}))}_getSpanContextFromOperationArguments(e,t,n,i=!1){const s={"db.system":"mongodb","db.name":e.dbName,"db.operation":t,"db.mongodb.collection":e.collectionName},o={op:"db",origin:"auto.db.mongo",description:t,data:s},r=ut[t],a=Array.isArray(this._describeOperations)?this._describeOperations.includes(t):this._describeOperations;if(!r||!a||!i)return o;try{if("mapReduce"===t){const[e,t]=n;s[r[0]]="string"==typeof e?e:e.name||"",s[r[1]]="string"==typeof t?t:t.name||""}else for(let e=0;e(i||(i=t.config),e.apply(t,n))})}catch(e){C&&c.vF.error("Mysql Integration was unable to instrument `mysql` config.")}function s(e){if(!e)return;const t=i?{"server.address":i.host,"server.port":i.port,"db.user":i.user}:{};Object.keys(t).forEach((n=>{e.setAttribute(n,t[n])})),e.end()}(0,ve.GS)(n,"createQuery",(function(e){return function(n,i,o){const r=tt([t().getScope().getSpan(),"optionalAccess",e=>e.startChild,"call",e=>e({description:"string"==typeof n?n:n.sql,op:"db",origin:"auto.db.mysql",data:{"db.system":"mysql"}})]);if("function"==typeof o)return e.call(this,n,i,(function(e,t,n){s(r),o(e,t,n)}));if("function"==typeof i)return e.call(this,n,(function(e,t,n){s(r),i(e,t,n)}));const a=e.call(this,n,i);return a.on("end",(()=>{s(r)})),a}}))}}It.__initStatic();class pt{static __initStatic(){this.id="Postgres"}constructor(e={}){this.name=pt.id,this._usePgNative=!!e.usePgNative,this._module=e.module}loadDependency(){return this._module=this._module||(0,nt.Vw)("pg")}setupOnce(e,t){if(st(t))return void(C&&c.vF.log("Postgres Integration is skipped because of instrumenter configuration."));const n=this.loadDependency();if(!n)return void(C&&c.vF.error("Postgres Integration was unable to require `pg` package."));const i=this._usePgNative?tt([n,"access",e=>e.native,"optionalAccess",e=>e.Client]):n.Client;i?(0,ve.GS)(i.prototype,"query",(function(e){return function(n,i,s){const o=t().getScope().getSpan(),r={"db.system":"postgresql"};try{this.database&&(r["db.name"]=this.database),this.host&&(r["server.address"]=this.host),this.port&&(r["server.port"]=this.port),this.user&&(r["db.user"]=this.user)}catch(e){}const a=tt([o,"optionalAccess",e=>e.startChild,"call",e=>e({description:"string"==typeof n?n:n.text,op:"db",origin:"auto.db.postgres",data:r})]);if("function"==typeof s)return e.call(this,n,i,(function(e,t){tt([a,"optionalAccess",e=>e.end,"call",e=>e()]),s(e,t)}));if("function"==typeof i)return e.call(this,n,(function(e,t){tt([a,"optionalAccess",e=>e.end,"call",e=>e()]),i(e,t)}));const c=void 0!==i?e.call(this,n,i):e.call(this,n);return(0,g.Qg)(c)?c.then((e=>(tt([a,"optionalAccess",e=>e.end,"call",e=>e()]),e))):(tt([a,"optionalAccess",e=>e.end,"call",e=>e()]),c)}})):C&&c.vF.error("Postgres Integration was unable to access 'pg-native' bindings.")}}pt.__initStatic();class Ct{static __initStatic(){this.id="Prisma"}constructor(e={}){if(this.name=Ct.id,(t=e.client)&&t.$use&&!e.client._sentryInstrumented){(0,ve.my)(e.client,"_sentryInstrumented",!0);const t={};try{const n=e.client._engineConfig;if(n){const{activeProvider:e,clientVersion:i}=n;e&&(t["db.system"]=e),i&&(t["db.prisma.version"]=i)}}catch(e){}e.client.$use(((e,n)=>{if(st(We.BF))return n(e);const i=e.action,s=e.model;return(0,fe.Lk)({name:s?`${s} ${i}`:i,onlyIfParent:!0,op:"db.prisma",attributes:{[r.JD]:"auto.db.prisma"},data:{...t,"db.operation":i}},(()=>n(e)))}))}else C&&c.vF.warn("Unsupported Prisma client provided to PrismaIntegration. Provided client:",e.client);var t}setupOnce(){}}Ct.__initStatic();const ht=class{constructor(e){this.name=Pe,this._hasSetTracePropagationTargets=!1,(0,s.U)(),C&&(this._hasSetTracePropagationTargets=!(!e||!e.tracePropagationTargets&&!e.tracingOrigins)),this.options={...Me,...e},void 0!==this.options._experiments.enableLongTask&&(this.options.enableLongTask=this.options._experiments.enableLongTask),e&&!e.tracePropagationTargets&&e.tracingOrigins&&(this.options.tracePropagationTargets=e.tracingOrigins),this._collectWebVitals=ye(),this._interactionIdToRouteNameMapping={},this.options.enableInp&&function(e,t){if(Ie()&&ae.k3){const n=function(e,t){return n=({metric:n})=>{if(void 0===n.value)return;const i=n.entries.find((e=>e.duration===n.value&&void 0!==Ze[e.name])),s=(0,a.KU)();if(!i||!s)return;const o=Ze[i.name],r=s.getOptions(),l=be(ae.k3+i.startTime),g=be(n.value),d=void 0!==i.interactionId?e[i.interactionId]:void 0;if(void 0===d)return;const{routeName:u,parentContext:I,activeTransaction:p,user:h,replayId:y}=d,Z=void 0!==h?h.email||h.id||h.ip_address:void 0,G=void 0!==p?p.getProfileId():void 0,B=new ie.L({startTimestamp:l,endTimestamp:l+g,op:`ui.interaction.${o}`,name:b(i.target),attributes:{release:r.release,environment:r.environment,transaction:u,...void 0!==Z&&""!==Z?{user:Z}:{},...void 0!==G?{profile_id:G}:{},...void 0!==y?{replay_id:y}:{}},exclusiveTime:n.value,measurements:{inp:{value:n.value,unit:"millisecond"}}}),A=function(e,t,n){if(!(0,oe.w)(t))return!1;let i;return i=void 0!==e&&"function"==typeof t.tracesSampler?t.tracesSampler({transactionContext:e,name:e.name,parentSampled:e.parentSampled,attributes:{...e.data,...e.attributes},location:m.location}):void 0!==e&&void 0!==e.sampled?e.sampled:void 0!==t.tracesSampleRate?t.tracesSampleRate:1,(0,re.v)(i)?!0===i?n:!1===i?0:i*n:(C&&c.vF.warn("[Tracing] Discarding interaction span because of invalid sample rate."),!1)}(I,r,t);if(A&&Math.random(){C&&c.vF.error("Error while sending interaction:",e)}))}},ee("inp",n,$,Q);var n}(e,t);return()=>{n()}}}(this._interactionIdToRouteNameMapping,this.options.interactionsSampleRate),this.options.enableLongTask&&j("longtask",(({entries:e})=>{for(const t of e){const e=(0,o.Z7)();if(!e)return;const n=be(ae.k3+t.startTime),i=be(t.duration);e.startChild({description:"Main UI thread blocked",op:"ui.long-task",origin:"auto.ui.browser.metrics",startTimestamp:n,endTimestamp:n+i})}})),this.options._experiments.enableInteractions&&j("event",(({entries:e})=>{for(const t of e){const e=(0,o.Z7)();if(!e)return;if("click"===t.name){const n=be(ae.k3+t.startTime),i=be(t.duration),s={description:b(t.target),op:`ui.interaction.${t.name}`,origin:"auto.ui.browser.metrics",startTimestamp:n,endTimestamp:n+i},o=p(t.target);o&&(s.attributes={"ui.component_name":o}),e.startChild(s)}}})),this._latestRoute={name:void 0,context:void 0}}setupOnce(e,t){this._getCurrentHub=t;const n=t().getClient(),i=n&&n.getOptions(),{routingInstrumentation:s,startTransactionOnLocationChange:r,startTransactionOnPageLoad:a,markBackgroundTransactions:l,traceFetch:g,traceXHR:d,shouldCreateSpanForRequest:u,enableHTTPTimings:b,_experiments:I}=this.options,p=i&&i.tracePropagationTargets,y=p||this.options.tracePropagationTargets;C&&this._hasSetTracePropagationTargets&&p&&c.vF.warn("[Tracing] The `tracePropagationTargets` option was set in the BrowserTracing integration and top level `Sentry.init`. The top level `Sentry.init` value is being used."),s((e=>{const n=this._createRouteTransaction(e);return this.options._experiments.onStartRouteTransaction&&this.options._experiments.onStartRouteTransaction(n,e,t),n}),a,r),l&&(m.document?m.document.addEventListener("visibilitychange",(()=>{const e=(0,o.Z7)();if(m.document.hidden&&e){const t="cancelled",{op:n,status:i}=(0,h.et)(e);C&&c.vF.log(`[Tracing] Transaction: ${t} -> since tab moved to the background, op: ${n}`),i||e.setStatus(t),e.setTag("visibilitychange","document.hidden"),e.end()}})):C&&c.vF.warn("[Tracing] Could not set up background tab detection due to lack of global document")),I.enableInteractions&&this._registerInteractionListener(),this.options.enableInp&&this._registerInpInteractionListener(),Ue({traceFetch:g,traceXHR:d,tracePropagationTargets:y,shouldCreateSpanForRequest:u,enableHTTPTimings:b})}_createRouteTransaction(e){if(!this._getCurrentHub)return void(C&&c.vF.warn(`[Tracing] Did not create ${e.op} transaction because _getCurrentHub is invalid.`));const t=this._getCurrentHub(),{beforeNavigate:n,idleTimeout:i,finalTimeout:r,heartbeatInterval:a}=this.options,g="pageload"===e.op;let d;if(g){const t=g?De("sentry-trace"):"",n=g?De("baggage"):void 0,{traceId:i,dsc:s,parentSpanId:o,sampled:r}=(0,l.kM)(t,n);d={traceId:i,parentSpanId:o,parentSampled:r,...e,metadata:{...e.metadata,dynamicSamplingContext:s},trimEnd:!0}}else d={trimEnd:!0,...e};const u="function"==typeof n?n(d):d,I=void 0===u?{...d,sampled:!1}:u;I.metadata=I.name!==d.name?{...I.metadata,source:"custom"}:I.metadata,this._latestRoute.name=I.name,this._latestRoute.context=I,!1===I.sampled&&C&&c.vF.log(`[Tracing] Will not send ${I.op} transaction because of beforeNavigate.`),C&&c.vF.log(`[Tracing] Starting ${I.op} transaction on scope`);const{location:p}=m,y=(0,s.p)(t,I,i,r,!0,{location:p},a,g);return g&&m.document&&(m.document.addEventListener("readystatechange",(()=>{["interactive","complete"].includes(m.document.readyState)&&y.sendAutoFinishSignal()})),["interactive","complete"].includes(m.document.readyState)&&y.sendAutoFinishSignal()),y.registerBeforeFinishCallback((e=>{this._collectWebVitals(),function(e){const t=Ie();if(!t||!m.performance.getEntries||!ae.k3)return;C&&c.vF.log("[Tracing] Adding & adjusting spans using Performance API");const n=be(ae.k3),i=t.getEntries(),{op:s,start_timestamp:r}=(0,h.et)(e);if(i.slice(he).forEach((t=>{const i=be(t.startTime),s=be(t.duration);if(!("navigation"===e.op&&r&&n+i{Ge(e,t,i,n)})),Ge(e,t,"secureConnection",n,"TLS/SSL","connectEnd"),Ge(e,t,"fetch",n,"cache","domainLookupStart"),Ge(e,t,"domainLookup",n,"DNS"),function(e,t,n){t.responseEnd&&(ue(e,{op:"browser",origin:"auto.browser.browser.metrics",description:"request",startTimestamp:n+be(t.requestStart),endTimestamp:n+be(t.responseEnd)}),ue(e,{op:"browser",origin:"auto.browser.browser.metrics",description:"response",startTimestamp:n+be(t.responseStart),endTimestamp:n+be(t.responseEnd)}))}(e,t,n)}(e,t,n);break;case"mark":case"paint":case"measure":{!function(e,t,n,i,s){const o=s+n,r=o+i;ue(e,{description:t.name,endTimestamp:r,op:t.entryType,origin:"auto.resource.browser.metrics",startTimestamp:o})}(e,t,i,s,n);const o=v(),r=t.startTime{if(!me[e]||!r||n>=r)return;const t=me[e].value,i=n+be(t),s=Math.abs(1e3*(i-r)),o=s-t;C&&c.vF.log(`[Measurements] Normalized ${e} from ${t} to ${s} (${o})`),me[e].value=s}));const t=me["mark.fid"];t&&me.fid&&(ue(e,{description:"first input delay",endTimestamp:t.value+be(me.fid.value),op:"ui.action",origin:"auto.ui.browser.metrics",startTimestamp:t.value}),delete me["mark.fid"]),"fcp"in me||delete me.cls,Object.keys(me).forEach((e=>{!function(e,t,n){const i=(0,o.Z7)();i&&i.setMeasurement(e,t,n)}(e,me[e].value,me[e].unit)})),function(e){pe&&(C&&c.vF.log("[Measurements] Adding LCP Data"),pe.element&&e.setTag("lcp.element",b(pe.element)),pe.id&&e.setTag("lcp.id",pe.id),pe.url&&e.setTag("lcp.url",pe.url.trim().slice(0,200)),e.setTag("lcp.size",pe.size)),Ce&&Ce.sources&&(C&&c.vF.log("[Measurements] Adding CLS Data"),Ce.sources.forEach(((t,n)=>e.setTag(`cls.source.${n+1}`,b(t.node)))))}(e)}pe=void 0,Ce=void 0,me={}}(e)})),y}_registerInteractionListener(){let e;const t=()=>{const{idleTimeout:t,finalTimeout:n,heartbeatInterval:i}=this.options,a="ui.action.click",l=(0,o.Z7)();if(l&&l.op&&["navigation","pageload"].includes(l.op))return void(C&&c.vF.warn(`[Tracing] Did not create ${a} transaction because a pageload or navigation transaction is in progress.`));if(e&&(e.setFinishReason("interactionInterrupted"),e.end(),e=void 0),!this._getCurrentHub)return void(C&&c.vF.warn(`[Tracing] Did not create ${a} transaction because _getCurrentHub is invalid.`));if(!this._latestRoute.name)return void(C&&c.vF.warn(`[Tracing] Did not create ${a} transaction because _latestRouteName is missing.`));const g=this._getCurrentHub(),{location:d}=m,u={name:this._latestRoute.name,op:a,trimEnd:!0,data:{[r.i_]:this._latestRoute.context?qe(this._latestRoute.context):"url"}};e=(0,s.p)(g,u,t,n,!0,{location:d},i)};["click"].forEach((e=>{m.document&&addEventListener(e,t,{once:!1,capture:!0})}))}_registerInpInteractionListener(){const e=({entries:e})=>{const t=(0,a.KU)(),n=void 0!==t&&void 0!==t.getIntegrationByName?t.getIntegrationByName("Replay"):void 0,i=void 0!==n?n.getReplayId():void 0,s=(0,o.Z7)(),r=(0,a.o5)(),c=void 0!==r?r.getUser():void 0;e.forEach((e=>{if(function(e){return"duration"in e}(e)){const t=e.interactionId;if(void 0===t)return;const n=this._interactionIdToRouteNameMapping[t],o=e.duration,r=e.startTime,a=Object.keys(this._interactionIdToRouteNameMapping),l=a.length>0?a.reduce(((e,t)=>this._interactionIdToRouteNameMapping[e].durationthis._interactionIdToRouteNameMapping[e])).some((e=>e.duration===o&&e.startTime===r)))return;if(!t)return;if(n)n.duration=Math.max(n.duration,o);else if(a.length<10||void 0===l||o>this._interactionIdToRouteNameMapping[l].duration){const e=this._latestRoute.name,n=this._latestRoute.context;e&&n&&(l&&Object.keys(this._interactionIdToRouteNameMapping).length>=10&&delete this._interactionIdToRouteNameMapping[l],this._interactionIdToRouteNameMapping[t]={routeName:e,duration:o,parentContext:n,user:c,activeTransaction:s,replayId:i,startTime:r})}}}))};j("event",e),j("first-input",e)}},mt=$e.l,yt=o.Z7,Zt=o.nc,Gt=Ae.o6,Bt=et.Z,At=ie.L,Wt=Pe,ft=ze,Vt=oe.w,vt=le,Rt=l.MI,Yt=i.zX,Xt=Ue,Ht=s.p,St=Ae.Fp,Nt={BrowserTracing:ht,Apollo:ot,Express:at,GraphQL:gt,Mongo:bt,Mysql:It,Postgres:pt,Prisma:Ct};("undefined"==typeof __SENTRY_TRACING__||__SENTRY_TRACING__)&&(0,$e.l)()},5584:(e,t,n)=>{"use strict";n.d(t,{De:()=>g,yD:()=>l});var i=n(5644),s=n(3816),o=n(7412);const r="sentry-",a=/^sentry-/,c=8192;function l(e){if(!(0,s.Kg)(e)&&!Array.isArray(e))return;let t={};if(Array.isArray(e))t=e.reduce(((e,t)=>{const n=d(t);for(const t of Object.keys(n))e[t]=n[t];return e}),{});else{if(!e)return;t=d(e)}const n=Object.entries(t).reduce(((e,[t,n])=>(t.match(a)&&(e[t.slice(r.length)]=n),e)),{});return Object.keys(n).length>0?n:void 0}function g(e){if(e)return function(e){if(0!==Object.keys(e).length)return Object.entries(e).reduce(((e,[t,n],s)=>{const r=`${encodeURIComponent(t)}=${encodeURIComponent(n)}`,a=0===s?r:`${e},${r}`;return a.length>c?(i.T&&o.vF.warn(`Not adding key: ${t} with val: ${n} to baggage header due to exceeding baggage size limits.`),e):a}),"")}(Object.entries(e).reduce(((e,[t,n])=>(n&&(e[`${r}${t}`]=n),e)),{}))}function d(e){return e.split(",").map((e=>e.split("=").map((e=>decodeURIComponent(e.trim()))))).reduce(((e,[t,n])=>(e[t]=n,e)),{})}},853:(e,t,n)=>{"use strict";function i(e){let t,n=e[0],i=1;for(;in.call(t,...e))),t=void 0)}return n}n.d(t,{z:()=>i})},5644:(e,t,n)=>{"use strict";n.d(t,{T:()=>i});const i="undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__},3816:(e,t,n)=>{"use strict";n.d(t,{Kg:()=>r,L2:()=>h,NF:()=>a,Qd:()=>l,Qg:()=>b,bJ:()=>s,gd:()=>u,mE:()=>I,sO:()=>c,tH:()=>C,vq:()=>d,xH:()=>g,yr:()=>p});const i=Object.prototype.toString;function s(e){switch(i.call(e)){case"[object Error]":case"[object Exception]":case"[object DOMException]":return!0;default:return C(e,Error)}}function o(e,t){return i.call(e)===`[object ${t}]`}function r(e){return o(e,"String")}function a(e){return"object"==typeof e&&null!==e&&"__sentry_template_string__"in e&&"__sentry_template_values__"in e}function c(e){return null===e||a(e)||"object"!=typeof e&&"function"!=typeof e}function l(e){return o(e,"Object")}function g(e){return"undefined"!=typeof Event&&C(e,Event)}function d(e){return"undefined"!=typeof Element&&C(e,Element)}function u(e){return o(e,"RegExp")}function b(e){return Boolean(e&&e.then&&"function"==typeof e.then)}function I(e){return l(e)&&"nativeEvent"in e&&"preventDefault"in e&&"stopPropagation"in e}function p(e){return"number"==typeof e&&e!=e}function C(e,t){try{return e instanceof t}catch(e){return!1}}function h(e){return!("object"!=typeof e||null===e||!e.__isVue&&!e._isVue)}},7412:(e,t,n)=>{"use strict";n.d(t,{Ow:()=>o,Z9:()=>r,pq:()=>a,vF:()=>c});var i=n(5644),s=n(6341);const o=["debug","info","warn","error","log","assert","trace"],r={};function a(e){if(!("console"in s.OW))return e();const t=s.OW.console,n={},i=Object.keys(r);i.forEach((e=>{const i=r[e];n[e]=t[e],t[e]=i}));try{return e()}finally{i.forEach((e=>{t[e]=n[e]}))}}const c=function(){let e=!1;const t={enable:()=>{e=!0},disable:()=>{e=!1},isEnabled:()=>e};return i.T?o.forEach((n=>{t[n]=(...t)=>{e&&a((()=>{s.OW.console[n](`Sentry Logger [${n}]:`,...t)}))}})):o.forEach((e=>{t[e]=()=>{}})),t}()},6936:(e,t,n)=>{"use strict";n.d(t,{$X:()=>c,GR:()=>I,M6:()=>g,db:()=>b,eJ:()=>r,gO:()=>l,k9:()=>p,kf:()=>u});var i=n(4022),s=n(9653),o=n(6341);function r(){const e=o.OW,t=e.crypto||e.msCrypto;let n=()=>16*Math.random();try{if(t&&t.randomUUID)return t.randomUUID().replace(/-/g,"");t&&t.getRandomValues&&(n=()=>{const e=new Uint8Array(1);return t.getRandomValues(e),e[0]})}catch(e){}return([1e7]+1e3+4e3+8e3+1e11).replace(/[018]/g,(e=>(e^(15&n())>>e/4).toString(16)))}function a(e){return e.exception&&e.exception.values?e.exception.values[0]:void 0}function c(e){const{message:t,event_id:n}=e;if(t)return t;const i=a(e);return i?i.type&&i.value?`${i.type}: ${i.value}`:i.type||i.value||n||"":n||""}function l(e,t,n){const i=e.exception=e.exception||{},s=i.values=i.values||[],o=s[0]=s[0]||{};o.value||(o.value=t||""),o.type||(o.type=n||"Error")}function g(e,t){const n=a(e);if(!n)return;const i=n.mechanism;if(n.mechanism={type:"generic",handled:!0,...i,...t},t&&"data"in t){const e={...i&&i.data,...t.data};n.mechanism.data=e}}const d=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;function u(e){const t=e.match(d)||[],n=parseInt(t[1],10),i=parseInt(t[2],10),s=parseInt(t[3],10);return{buildmetadata:t[5],major:isNaN(n)?void 0:n,minor:isNaN(i)?void 0:i,patch:isNaN(s)?void 0:s,prerelease:t[4]}}function b(e,t,n=5){if(void 0===t.lineno)return;const i=e.length,o=Math.max(Math.min(i-1,t.lineno-1),0);t.pre_context=e.slice(Math.max(0,o-n),o).map((e=>(0,s.nC)(e,0))),t.context_line=(0,s.nC)(e[Math.min(i-1,o)],t.colno||0),t.post_context=e.slice(Math.min(o+1,i),o+1+n).map((e=>(0,s.nC)(e,0)))}function I(e){if(e&&e.__sentry_captured__)return!0;try{(0,i.my)(e,"__sentry_captured__",!0)}catch(e){}return!1}function p(e){return Array.isArray(e)?e:[e]}},3903:(e,t,n)=>{"use strict";function i(e,t){return e.require(t)}function s(t){let n;try{n=i(e,t)}catch(e){}try{const{cwd:s}=i(e,"process");n=i(e,`${s()}/node_modules/${t}`)}catch(e){}return n}n.d(t,{Vw:()=>s,fj:()=>i}),e=n.hmd(e)},2181:(e,t,n)=>{"use strict";n.d(t,{S8:()=>r,cd:()=>a});var i=n(3816),s=n(4022),o=n(7930);function r(e,t=100,n=1/0){try{return c("",e,t,n)}catch(e){return{ERROR:`**non-serializable** (${e})`}}}function a(e,t=3,n=102400){const i=r(e,t);return s=i,function(e){return~-encodeURI(e).split(/%..|./).length}(JSON.stringify(s))>n?a(e,t-1,n):i;var s}function c(e,t,n=1/0,r=1/0,a=function(){const e="function"==typeof WeakSet,t=e?new WeakSet:[];return[function(n){if(e)return!!t.has(n)||(t.add(n),!1);for(let e=0;e=r){I[e]="[MaxProperties ~]";break}const t=C[e];I[e]=c(e,t,u-1,r,a),p++}return g(t),I}},4022:(e,t,n)=>{"use strict";n.d(t,{my:()=>d,W4:()=>I,Ce:()=>m,HF:()=>h,GS:()=>g,sp:()=>u,u4:()=>b});var i=n(3816);const s=(0,n(6341).VZ)(),o=80;function r(e,t){const n=e,o=[];let r,a,c,l,g;if(!n||!n.tagName)return"";if(s.HTMLElement&&n instanceof HTMLElement&&n.dataset&&n.dataset.sentryComponent)return n.dataset.sentryComponent;o.push(n.tagName.toLowerCase());const d=t&&t.length?t.filter((e=>n.getAttribute(e))).map((e=>[e,n.getAttribute(e)])):null;if(d&&d.length)d.forEach((e=>{o.push(`[${e[0]}="${e[1]}"]`)}));else if(n.id&&o.push(`#${n.id}`),r=n.className,r&&(0,i.Kg)(r))for(a=r.split(/\s+/),g=0;g`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`)).join("&")}function I(e){if((0,i.bJ)(e))return{message:e.message,name:e.name,stack:e.stack,...C(e)};if((0,i.xH)(e)){const t={type:e.type,target:p(e.target),currentTarget:p(e.currentTarget),...C(e)};return"undefined"!=typeof CustomEvent&&(0,i.tH)(e,CustomEvent)&&(t.detail=e.detail),t}return e}function p(e){try{return(0,i.vq)(e)?function(e,t={}){if(!e)return"";try{let n=e;const i=5,s=[];let a=0,c=0;const l=" > ",g=l.length;let d;const u=Array.isArray(t)?t:t.keyAttrs,b=!Array.isArray(t)&&t.maxStringLength||o;for(;n&&a++1&&c+s.length*g+d.length>=b));)s.push(d),c+=d.length,n=n.parentNode;return s.reverse().join(l)}catch(e){return""}}(e):Object.prototype.toString.call(e)}catch(e){return""}}function C(e){if("object"==typeof e&&null!==e){const t={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}return{}}function h(e,t=40){const n=Object.keys(I(e));if(n.sort(),!n.length)return"[object has no keys]";if(n[0].length>=t)return(0,l.xv)(n[0],t);for(let e=n.length;e>0;e--){const i=n.slice(0,e).join(", ");if(!(i.length>t))return e===n.length?i:(0,l.xv)(i,t)}return""}function m(e){return y(e,new Map)}function y(e,t){if(function(e){if(!(0,i.Qd)(e))return!1;try{const t=Object.getPrototypeOf(e).constructor.name;return!t||"Object"===t}catch(e){return!0}}(e)){const n=t.get(e);if(void 0!==n)return n;const i={};t.set(e,i);for(const n of Object.keys(e))void 0!==e[n]&&(i[n]=y(e[n],t));return i}if(Array.isArray(e)){const n=t.get(e);if(void 0!==n)return n;const i=[];return t.set(e,i),e.forEach((e=>{i.push(y(e,t))})),i}return e}},7930:(e,t,n)=>{"use strict";function i(e,t=!1){return!(t||e&&!e.startsWith("/")&&!e.match(/^[A-Z]:/)&&!e.startsWith(".")&&!e.match(/^[a-zA-Z]([a-zA-Z0-9.\-+])*:\/\//)||void 0===e||e.includes("node_modules/"))}function s(e){const t=/^\s*[-]{4,}$/,n=/at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/;return s=>{const o=s.match(n);if(o){let t,n,s,r,a;if(o[1]){s=o[1];let e=s.lastIndexOf(".");if("."===s[e-1]&&e--,e>0){t=s.slice(0,e),n=s.slice(e+1);const i=t.indexOf(".Module");i>0&&(s=s.slice(i+1),t=t.slice(0,i))}r=void 0}n&&(r=t,a=n),""===n&&(a=void 0,s=void 0),void 0===s&&(a=a||"",s=r?`${r}.${a}`:a);let c=o[2]&&o[2].startsWith("file://")?o[2].slice(7):o[2];const l="native"===o[5];return c&&c.match(/\/[A-Z]:/)&&(c=c.slice(1)),c||!o[5]||l||(c=o[5]),{filename:c,module:e?e(c):void 0,function:s,lineno:parseInt(o[3],10)||void 0,colno:parseInt(o[4],10)||void 0,in_app:i(c,l)}}if(s.match(t))return{filename:s}}}n.d(t,{gd:()=>c,qQ:()=>d,o:()=>u,vk:()=>l});const o=50,r=/\(error: (.*)\)/,a=/captureMessage|captureException/;function c(...e){const t=e.sort(((e,t)=>e[0]-t[0])).map((e=>e[1]));return(e,n=0)=>{const i=[],s=e.split("\n");for(let e=n;e1024)continue;const a=r.test(n)?n.replace(r,"$1"):n;if(!a.match(/\S*Error: /)){for(const e of t){const t=e(a);if(t){i.push(t);break}}if(i.length>=o)break}}return function(e){if(!e.length)return[];const t=Array.from(e);return/sentryWrapped/.test(t[t.length-1].function||"")&&t.pop(),t.reverse(),a.test(t[t.length-1].function||"")&&(t.pop(),a.test(t[t.length-1].function||"")&&t.pop()),t.slice(0,o).map((e=>({...e,filename:e.filename||t[t.length-1].filename,function:e.function||"?"})))}(i)}}function l(e){return Array.isArray(e)?c(...e):e}const g="";function d(e){try{return e&&"function"==typeof e&&e.name||g}catch(e){return g}}function u(e){return[90,s(e)]}},9653:(e,t,n)=>{"use strict";n.d(t,{Xr:()=>a,gt:()=>r,nC:()=>o,xv:()=>s});var i=n(3816);function s(e,t=0){return"string"!=typeof e||0===t||e.length<=t?e:`${e.slice(0,t)}...`}function o(e,t){let n=e;const i=n.length;if(i<=150)return n;t>i&&(t=i);let s=Math.max(t-60,0);s<5&&(s=0);let o=Math.min(s+140,i);return o>i-5&&(o=i),o===i&&(s=Math.max(o-140,0)),n=n.slice(s,o),s>0&&(n=`'{snip} ${n}`),ofunction(e,t,n=!1){return!!(0,i.Kg)(e)&&((0,i.gd)(t)?t.test(e):!!(0,i.Kg)(t)&&(n?e===t:e.includes(t)))}(e,t,n)))}},690:(e,t,n)=>{"use strict";n.d(t,{T2:()=>a,XW:()=>o,xg:()=>r});var i,s=n(3816);function o(e){return new a((t=>{t(e)}))}function r(e){return new a(((t,n)=>{n(e)}))}!function(e){e[e.PENDING=0]="PENDING",e[e.RESOLVED=1]="RESOLVED",e[e.REJECTED=2]="REJECTED"}(i||(i={}));class a{constructor(e){a.prototype.__init.call(this),a.prototype.__init2.call(this),a.prototype.__init3.call(this),a.prototype.__init4.call(this),this._state=i.PENDING,this._handlers=[];try{e(this._resolve,this._reject)}catch(e){this._reject(e)}}then(e,t){return new a(((n,i)=>{this._handlers.push([!1,t=>{if(e)try{n(e(t))}catch(e){i(e)}else n(t)},e=>{if(t)try{n(t(e))}catch(e){i(e)}else i(e)}]),this._executeHandlers()}))}catch(e){return this.then((e=>e),e)}finally(e){return new a(((t,n)=>{let i,s;return this.then((t=>{s=!1,i=t,e&&e()}),(t=>{s=!0,i=t,e&&e()})).then((()=>{s?n(i):t(i)}))}))}__init(){this._resolve=e=>{this._setResult(i.RESOLVED,e)}}__init2(){this._reject=e=>{this._setResult(i.REJECTED,e)}}__init3(){this._setResult=(e,t)=>{this._state===i.PENDING&&((0,s.Qg)(t)?t.then(this._resolve,this._reject):(this._state=e,this._value=t,this._executeHandlers()))}}__init4(){this._executeHandlers=()=>{if(this._state===i.PENDING)return;const e=this._handlers.slice();this._handlers=[],e.forEach((e=>{e[0]||(this._state===i.RESOLVED&&e[1](this._value),this._state===i.REJECTED&&e[2](this._value),e[0]=!0)}))}}}},9297:(e,t,n)=>{"use strict";n.d(t,{lu:()=>o,zf:()=>r});var i=n(6341);const s=1e3;function o(){return Date.now()/s}const r=function(){const{performance:e}=i.OW;if(!e||!e.now)return o;const t=Date.now()-e.now(),n=null==e.timeOrigin?t:e.timeOrigin;return()=>(n+e.now())/s}();let a;(()=>{const{performance:e}=i.OW;if(!e||!e.now)return void(a="none");const t=36e5,n=e.now(),s=Date.now(),o=e.timeOrigin?Math.abs(e.timeOrigin+n-s):t,r=o{"use strict";n.d(t,{E0:()=>a,TC:()=>l,kM:()=>c,nc:()=>r});var i=n(5584),s=n(6936);const o=new RegExp("^[ \\t]*([0-9a-f]{32})?-?([0-9a-f]{16})?-?([01])?[ \\t]*$");function r(e){if(!e)return;const t=e.match(o);if(!t)return;let n;return"1"===t[3]?n=!0:"0"===t[3]&&(n=!1),{traceId:t[1],parentSampled:n,parentSpanId:t[2]}}function a(e,t){const n=r(e),o=(0,i.yD)(t),{traceId:a,parentSpanId:c,parentSampled:l}=n||{};return n?{traceparentData:n,dynamicSamplingContext:o||{},propagationContext:{traceId:a||(0,s.eJ)(),parentSpanId:c||(0,s.eJ)().substring(16),spanId:(0,s.eJ)().substring(16),sampled:l,dsc:o||{}}}:{traceparentData:n,dynamicSamplingContext:void 0,propagationContext:{traceId:a||(0,s.eJ)(),spanId:(0,s.eJ)().substring(16)}}}function c(e,t){const n=r(e),o=(0,i.yD)(t),{traceId:a,parentSpanId:c,parentSampled:l}=n||{};return n?{traceId:a||(0,s.eJ)(),parentSpanId:c||(0,s.eJ)().substring(16),spanId:(0,s.eJ)().substring(16),sampled:l,dsc:o||{}}:{traceId:a||(0,s.eJ)(),spanId:(0,s.eJ)().substring(16)}}function l(e=(0,s.eJ)(),t=(0,s.eJ)().substring(16),n){let i="";return void 0!==n&&(i=n?"-1":"-0"),`${e}-${t}${i}`}},6341:(e,t,n)=>{"use strict";function i(e){return e&&e.Math==Math?e:void 0}n.d(t,{BY:()=>r,OW:()=>s,VZ:()=>o});const s="object"==typeof globalThis&&i(globalThis)||"object"==typeof window&&i(window)||"object"==typeof self&&i(self)||"object"==typeof global&&i(global)||function(){return this}()||{};function o(){return s}function r(e,t,n){const i=n||s,o=i.__SENTRY__=i.__SENTRY__||{};return o[e]||(o[e]=t())}},6284:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var n={grad:.9,turn:360,rad:360/(2*Math.PI)},i=function(e){return"string"==typeof e?e.length>0:"number"==typeof e},s=function(e,t,n){return void 0===t&&(t=0),void 0===n&&(n=Math.pow(10,t)),Math.round(n*e)/n+0},o=function(e,t,n){return void 0===t&&(t=0),void 0===n&&(n=1),e>n?n:e>t?e:t},r=function(e){return(e=isFinite(e)?e%360:0)>0?e:e+360},a=function(e){return{r:o(e.r,0,255),g:o(e.g,0,255),b:o(e.b,0,255),a:o(e.a)}},c=function(e){return{r:s(e.r),g:s(e.g),b:s(e.b),a:s(e.a,3)}},l=/^#([0-9a-f]{3,8})$/i,g=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},d=function(e){var t=e.r,n=e.g,i=e.b,s=e.a,o=Math.max(t,n,i),r=o-Math.min(t,n,i),a=r?o===t?(n-i)/r:o===n?2+(i-t)/r:4+(t-n)/r:0;return{h:60*(a<0?a+6:a),s:o?r/o*100:0,v:o/255*100,a:s}},u=function(e){var t=e.h,n=e.s,i=e.v,s=e.a;t=t/360*6,n/=100,i/=100;var o=Math.floor(t),r=i*(1-n),a=i*(1-(t-o)*n),c=i*(1-(1-t+o)*n),l=o%6;return{r:255*[i,a,r,r,c,i][l],g:255*[c,i,i,a,r,r][l],b:255*[r,r,c,i,i,a][l],a:s}},b=function(e){return{h:r(e.h),s:o(e.s,0,100),l:o(e.l,0,100),a:o(e.a)}},I=function(e){return{h:s(e.h),s:s(e.s),l:s(e.l),a:s(e.a,3)}},p=function(e){return u((n=(t=e).s,{h:t.h,s:(n*=((i=t.l)<50?i:100-i)/100)>0?2*n/(i+n)*100:0,v:i+n,a:t.a}));var t,n,i},C=function(e){return{h:(t=d(e)).h,s:(s=(200-(n=t.s))*(i=t.v)/100)>0&&s<200?n*i/100/(s<=100?s:200-s)*100:0,l:s/2,a:t.a};var t,n,i,s},h=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,m=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,y=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Z=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,G={string:[[function(e){var t=l.exec(e);return t?(e=t[1]).length<=4?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:4===e.length?s(parseInt(e[3]+e[3],16)/255,2):1}:6===e.length||8===e.length?{r:parseInt(e.substr(0,2),16),g:parseInt(e.substr(2,2),16),b:parseInt(e.substr(4,2),16),a:8===e.length?s(parseInt(e.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(e){var t=y.exec(e)||Z.exec(e);return t?t[2]!==t[4]||t[4]!==t[6]?null:a({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:void 0===t[7]?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(e){var t=h.exec(e)||m.exec(e);if(!t)return null;var i,s,o=b({h:(i=t[1],s=t[2],void 0===s&&(s="deg"),Number(i)*(n[s]||1)),s:Number(t[3]),l:Number(t[4]),a:void 0===t[5]?1:Number(t[5])/(t[6]?100:1)});return p(o)},"hsl"]],object:[[function(e){var t=e.r,n=e.g,s=e.b,o=e.a,r=void 0===o?1:o;return i(t)&&i(n)&&i(s)?a({r:Number(t),g:Number(n),b:Number(s),a:Number(r)}):null},"rgb"],[function(e){var t=e.h,n=e.s,s=e.l,o=e.a,r=void 0===o?1:o;if(!i(t)||!i(n)||!i(s))return null;var a=b({h:Number(t),s:Number(n),l:Number(s),a:Number(r)});return p(a)},"hsl"],[function(e){var t=e.h,n=e.s,s=e.v,a=e.a,c=void 0===a?1:a;if(!i(t)||!i(n)||!i(s))return null;var l=function(e){return{h:r(e.h),s:o(e.s,0,100),v:o(e.v,0,100),a:o(e.a)}}({h:Number(t),s:Number(n),v:Number(s),a:Number(c)});return u(l)},"hsv"]]},B=function(e,t){for(var n=0;n=.5},e.prototype.toHex=function(){return t=(e=c(this.rgba)).r,n=e.g,i=e.b,r=(o=e.a)<1?g(s(255*o)):"","#"+g(t)+g(n)+g(i)+r;var e,t,n,i,o,r},e.prototype.toRgb=function(){return c(this.rgba)},e.prototype.toRgbString=function(){return t=(e=c(this.rgba)).r,n=e.g,i=e.b,(s=e.a)<1?"rgba("+t+", "+n+", "+i+", "+s+")":"rgb("+t+", "+n+", "+i+")";var e,t,n,i,s},e.prototype.toHsl=function(){return I(C(this.rgba))},e.prototype.toHslString=function(){return t=(e=I(C(this.rgba))).h,n=e.s,i=e.l,(s=e.a)<1?"hsla("+t+", "+n+"%, "+i+"%, "+s+")":"hsl("+t+", "+n+"%, "+i+"%)";var e,t,n,i,s},e.prototype.toHsv=function(){return e=d(this.rgba),{h:s(e.h),s:s(e.s),v:s(e.v),a:s(e.a,3)};var e},e.prototype.invert=function(){return R({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},e.prototype.saturate=function(e){return void 0===e&&(e=.1),R(W(this.rgba,e))},e.prototype.desaturate=function(e){return void 0===e&&(e=.1),R(W(this.rgba,-e))},e.prototype.grayscale=function(){return R(W(this.rgba,-1))},e.prototype.lighten=function(e){return void 0===e&&(e=.1),R(V(this.rgba,e))},e.prototype.darken=function(e){return void 0===e&&(e=.1),R(V(this.rgba,-e))},e.prototype.rotate=function(e){return void 0===e&&(e=15),this.hue(this.hue()+e)},e.prototype.alpha=function(e){return"number"==typeof e?R({r:(t=this.rgba).r,g:t.g,b:t.b,a:e}):s(this.rgba.a,3);var t},e.prototype.hue=function(e){var t=C(this.rgba);return"number"==typeof e?R({h:e,s:t.s,l:t.l,a:t.a}):s(t.h)},e.prototype.isEqual=function(e){return this.toHex()===R(e).toHex()},e}(),R=function(e){return e instanceof v?e:new v(e)},Y=[];t.Colord=v,t.colord=R,t.extend=function(e){e.forEach((function(e){Y.indexOf(e)<0&&(e(v,G),Y.push(e))}))},t.getFormat=function(e){return A(e)[1]},t.random=function(){return new v({r:255*Math.random(),g:255*Math.random(),b:255*Math.random()})}},6022:e=>{!function(){"use strict";var t=[,function(e,t){function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n255)throw new Error("Not ascii. Base64.encode can only take ascii strings.");e[n]=s}}for(var r=[],a=null,c=null,l=null,g=null,d=0;d>2&63,c=(3&e[d])<<4;break;case 1:c|=e[d]>>4&15,l=(15&e[d])<<2;break;case 2:l|=e[d]>>6&3,g=63&e[d],r.push(i(a)),r.push(i(c)),r.push(i(l)),r.push(i(g)),a=null,c=null,l=null,g=null}return null!=a&&(r.push(i(a)),r.push(i(c)),null==l?r.push("="):r.push(i(l)),null==g&&r.push("=")),r.join("")},decode:function(e){var t=Math.floor(3*e.length/4);"="==e.charAt(e.length-1)&&(t--,"="==e.charAt(e.length-2)&&t--);for(var i,s=o(t),r=null,a=null,c=null,l=0,g=0;g>4,s[l++]=r,a=(15&d)<<4;break;case 2:d>=0&&(a|=d>>2,s[l++]=a,c=(3&d)<<6);break;case 3:d>=0&&(s[l++]=c|d)}}return s},newBinary:o};t.Base64=r},function(e){e.exports={_noYieldsAllowed:function(e){return e()}}},function(e,t){function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function i(e){return JSON.stringify(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=function e(t,s,o,r,a){var c=s[t];switch(n(c)){case"string":return i(c);case"number":return isFinite(c)?String(c):"null";case"boolean":return String(c);case"object":if(!c)return"null";var l,g=r+o,d=[];if(Array.isArray(c)||{}.hasOwnProperty.call(c,"callee")){for(var u=c.length,b=0;b0&&void 0!==arguments[0]&&arguments[0]?a:(0,o.convertMapToObject)(a)},r._getConverters=function(){return c};var l=function(e){for(var t=0;t=d.length||s!==d[i]||!r.equals(e[s],t[d[i]],n)||(i++,0))}))):(i=0,a=g.every((function(s){return!!(0,o.hasOwn)(t,s)&&!!r.equals(e[s],t[s],n)&&(i++,!0)}))),a&&i===d.length},r.clone=function(e){var t;if(!(0,o.isObject)(e))return e;if(null===e)return null;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return e;if(r.isBinary(e)){t=r.newBinary(e.length);for(var n=0;n{"use strict";var t=Object.prototype.hasOwnProperty,n="~";function i(){}function s(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,t,i,o,r){if("function"!=typeof i)throw new TypeError("The listener must be a function");var a=new s(i,o||e,r),c=n?n+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function r(e,t){0==--e._eventsCount?e._events=new i:delete e._events[t]}function a(){this._events=new i,this._eventsCount=0}Object.create&&(i.prototype=Object.create(null),(new i).__proto__||(n=!1)),a.prototype.eventNames=function(){var e,i,s=[];if(0===this._eventsCount)return s;for(i in e=this._events)t.call(e,i)&&s.push(n?i.slice(1):i);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(e)):s},a.prototype.listeners=function(e){var t=n?n+e:e,i=this._events[t];if(!i)return[];if(i.fn)return[i.fn];for(var s=0,o=i.length,r=new Array(o);s{"use strict";e.exports=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var i,s,o;if(Array.isArray(t)){if((i=t.length)!=n.length)return!1;for(s=i;0!=s--;)if(!e(t[s],n[s]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((i=(o=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(s=i;0!=s--;)if(!Object.prototype.hasOwnProperty.call(n,o[s]))return!1;for(s=i;0!=s--;){var r=o[s];if(!e(t[r],n[r]))return!1}return!0}return t!=t&&n!=n}},4865:e=>{"use strict";const t=(e,t,i,s)=>{if("length"===i||"prototype"===i)return;if("arguments"===i||"caller"===i)return;const o=Object.getOwnPropertyDescriptor(e,i),r=Object.getOwnPropertyDescriptor(t,i);!n(o,r)&&s||Object.defineProperty(e,i,r)},n=function(e,t){return void 0===e||e.configurable||e.writable===t.writable&&e.enumerable===t.enumerable&&e.configurable===t.configurable&&(e.writable||e.value===t.value)},i=(e,t)=>`/* Wrapped ${e}*/\n${t}`,s=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),o=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name");e.exports=(e,n,{ignoreNonConfigurable:r=!1}={})=>{const{name:a}=e;for(const i of Reflect.ownKeys(n))t(e,n,i,r);return((e,t)=>{const n=Object.getPrototypeOf(t);n!==Object.getPrototypeOf(e)&&Object.setPrototypeOf(e,n)})(e,n),((e,t,n)=>{const r=""===n?"":`with ${n.trim()}() `,a=i.bind(null,r,t.toString());Object.defineProperty(a,"name",o),Object.defineProperty(e,"toString",{...s,value:a})})(e,n,a),e}},4617:e=>{"use strict";e.exports=(e,t)=>(t=t||(()=>{}),e.then((e=>new Promise((e=>{e(t())})).then((()=>e))),(e=>new Promise((e=>{e(t())})).then((()=>{throw e})))))},3290:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=n(228),s=n(7685),o=n(4774),r=()=>{},a=new s.TimeoutError;t.default=class extends i{constructor(e){var t,n,i,s;if(super(),this._intervalCount=0,this._intervalEnd=0,this._pendingCount=0,this._resolveEmpty=r,this._resolveIdle=r,!("number"==typeof(e=Object.assign({carryoverConcurrencyCount:!1,intervalCap:1/0,interval:0,concurrency:1/0,autoStart:!0,queueClass:o.default},e)).intervalCap&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${null!==(n=null===(t=e.intervalCap)||void 0===t?void 0:t.toString())&&void 0!==n?n:""}\` (${typeof e.intervalCap})`);if(void 0===e.interval||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${null!==(s=null===(i=e.interval)||void 0===i?void 0:i.toString())&&void 0!==s?s:""}\` (${typeof e.interval})`);this._carryoverConcurrencyCount=e.carryoverConcurrencyCount,this._isIntervalIgnored=e.intervalCap===1/0||0===e.interval,this._intervalCap=e.intervalCap,this._interval=e.interval,this._queue=new e.queueClass,this._queueClass=e.queueClass,this.concurrency=e.concurrency,this._timeout=e.timeout,this._throwOnTimeout=!0===e.throwOnTimeout,this._isPaused=!1===e.autoStart}get _doesIntervalAllowAnother(){return this._isIntervalIgnored||this._intervalCount{this._onResumeInterval()}),t)),!0;this._intervalCount=this._carryoverConcurrencyCount?this._pendingCount:0}return!1}_tryToStartAnother(){if(0===this._queue.size)return this._intervalId&&clearInterval(this._intervalId),this._intervalId=void 0,this._resolvePromises(),!1;if(!this._isPaused){const e=!this._isIntervalPaused();if(this._doesIntervalAllowAnother&&this._doesConcurrentAllowAnother){const t=this._queue.dequeue();return!!t&&(this.emit("active"),t(),e&&this._initializeIntervalIfNeeded(),!0)}}return!1}_initializeIntervalIfNeeded(){this._isIntervalIgnored||void 0!==this._intervalId||(this._intervalId=setInterval((()=>{this._onInterval()}),this._interval),this._intervalEnd=Date.now()+this._interval)}_onInterval(){0===this._intervalCount&&0===this._pendingCount&&this._intervalId&&(clearInterval(this._intervalId),this._intervalId=void 0),this._intervalCount=this._carryoverConcurrencyCount?this._pendingCount:0,this._processQueue()}_processQueue(){for(;this._tryToStartAnother(););}get concurrency(){return this._concurrency}set concurrency(e){if(!("number"==typeof e&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this._concurrency=e,this._processQueue()}async add(e,t={}){return new Promise(((n,i)=>{this._queue.enqueue((async()=>{this._pendingCount++,this._intervalCount++;try{const o=void 0===this._timeout&&void 0===t.timeout?e():s.default(Promise.resolve(e()),void 0===t.timeout?this._timeout:t.timeout,(()=>{(void 0===t.throwOnTimeout?this._throwOnTimeout:t.throwOnTimeout)&&i(a)}));n(await o)}catch(e){i(e)}this._next()}),t),this._tryToStartAnother(),this.emit("add")}))}async addAll(e,t){return Promise.all(e.map((async e=>this.add(e,t))))}start(){return this._isPaused?(this._isPaused=!1,this._processQueue(),this):this}pause(){this._isPaused=!0}clear(){this._queue=new this._queueClass}async onEmpty(){if(0!==this._queue.size)return new Promise((e=>{const t=this._resolveEmpty;this._resolveEmpty=()=>{t(),e()}}))}async onIdle(){if(0!==this._pendingCount||0!==this._queue.size)return new Promise((e=>{const t=this._resolveIdle;this._resolveIdle=()=>{t(),e()}}))}get size(){return this._queue.size}sizeBy(e){return this._queue.filter(e).length}get pending(){return this._pendingCount}get isPaused(){return this._isPaused}get timeout(){return this._timeout}set timeout(e){this._timeout=e}}},9998:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,n){let i=0,s=e.length;for(;s>0;){const o=s/2|0;let r=i+o;n(e[r],t)<=0?(i=++r,s-=o+1):s=o}return i}},4774:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=n(9998);t.default=class{constructor(){this._queue=[]}enqueue(e,t){const n={priority:(t=Object.assign({priority:0},t)).priority,run:e};if(this.size&&this._queue[this.size-1].priority>=t.priority)return void this._queue.push(n);const s=i.default(this._queue,n,((e,t)=>t.priority-e.priority));this._queue.splice(s,0,n)}dequeue(){const e=this._queue.shift();return null==e?void 0:e.run}filter(e){return this._queue.filter((t=>t.priority===e.priority)).map((e=>e.run))}get size(){return this._queue.length}}},7685:(e,t,n)=>{"use strict";const i=n(4617);class s extends Error{constructor(e){super(e),this.name="TimeoutError"}}const o=(e,t,n)=>new Promise(((o,r)=>{if("number"!=typeof t||t<0)throw new TypeError("Expected `milliseconds` to be a positive number");if(t===1/0)return void o(e);const a=setTimeout((()=>{if("function"==typeof n){try{o(n())}catch(e){r(e)}return}const i=n instanceof Error?n:new s("string"==typeof n?n:`Promise timed out after ${t} milliseconds`);"function"==typeof e.cancel&&e.cancel(),r(i)}),t);i(e.then(o,r),(()=>{clearTimeout(a)}))}));e.exports=o,e.exports.default=o,e.exports.TimeoutError=s},7194:e=>{"use strict";e.exports=require("dgram")},1637:e=>{"use strict";e.exports=require("diagnostics_channel")},1943:e=>{"use strict";e.exports=require("fs/promises")},8611:e=>{"use strict";e.exports=require("http")},5692:e=>{"use strict";e.exports=require("https")},264:e=>{"use strict";e.exports=require("inspector")},9278:e=>{"use strict";e.exports=require("net")},6928:e=>{"use strict";e.exports=require("path")},2203:e=>{"use strict";e.exports=require("stream")},7016:e=>{"use strict";e.exports=require("url")},4581:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},4326:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.runEntrypoint=void 0;const i=n(1635),s=n(9967),o=i.__importDefault(n(1943)),r=n(360),a=n(2710);n(5664);const c=n(4044),l=i.__importDefault(n(6928));let g,d=!1;t.runEntrypoint=function(e,t){Promise.resolve().then((async()=>{if(d)throw new Error("runEntrypoint can only be called once");d=!0;const n=process.env.MODULE_MANIFEST;if(!n)throw new Error("Module initialise is missing MODULE_MANIFEST");const i=await o.default.readFile(n),u=JSON.parse(i.toString());if(u.runtime?.api!==s.HostApiNodeJsIpc)throw new Error("Module manifest 'api' mismatch");if(!u.runtime.apiVersion)throw new Error("Module manifest 'apiVersion' missing");let b=u.runtime.apiVersion;if("0.0.0"===b)try{const e=await o.default.readFile(l.default.join(__dirname,"../package.json")),t=JSON.parse(e.toString());"@companion-module/base"===t.name&&(b=t.version)}catch(e){throw new Error("Failed to determine module api version")}if(!process.send)throw new Error("Module is not being run with ipc");console.log(`Starting up module class: ${e.name}`);const I=process.env.CONNECTION_ID;if("string"!=typeof I||!I)throw new Error("Module initialise is missing CONNECTION_ID");const p=process.env.VERIFICATION_TOKEN;if("string"!=typeof p||!p)throw new Error("Module initialise is missing VERIFICATION_TOKEN");const C=process.env.SENTRY_DSN,h=process.env.SENTRY_USERID,m=process.env.SENTRY_COMPANION_VERSION;C&&h&&"https://"==C.substring(0,8)?(console.log("Sentry enabled"),(0,a.init)({dsn:C,release:`${u.name}@${u.version}`,beforeSend:e=>(e.exception&&console.log("sentry","error",e.exception),e)}),(0,a.configureScope)((e=>{e.setUser({id:h}),e.setTag("companion",m)}))):console.log("Sentry disabled");const y=new c.IpcWrapper({},(e=>{process.send(e)}),5e3);process.once("message",(e=>{y.receivedMessage(e)})),g=new e((0,r.literal)({id:I,upgradeScripts:t,_isInstanceBaseProps:!0})),y.sendWithCb("register",{apiVersion:b,connectionId:I,verificationToken:p}).then((()=>{console.log("Module-host accepted registration")}),(e=>{console.error("Module registration failed",e),process.exit(11)}))})).catch((e=>{console.error("Failed to startup module:"),console.error(e.stack||e.message),process.exit(1)}))}},6160:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.UDPHelper=t.TelnetHelper=t.TCPHelper=void 0;var i=n(8895);Object.defineProperty(t,"TCPHelper",{enumerable:!0,get:function(){return i.TCPHelper}});var s=n(1118);Object.defineProperty(t,"TelnetHelper",{enumerable:!0,get:function(){return s.TelnetHelper}});var o=n(6259);Object.defineProperty(t,"UDPHelper",{enumerable:!0,get:function(){return o.UDPHelper}})},8895:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TCPHelper=void 0;const i=n(1635).__importDefault(n(9278)),s=n(228),o=n(1400);class r extends s.EventEmitter{#e;#t;_socket;#n;#i=!1;#s=!1;#o=!1;#r;#a;#c;get isConnected(){return this.#i}get isConnecting(){return this.#s}get isDestroyed(){return this.#o}constructor(e,t,n){super(),this.#e=e,this.#t=t,this.#n={reconnect_interval:2e3,reconnect:!0,...n},this._socket=new i.default.Socket,this._socket.setKeepAlive(!0),this._socket.setNoDelay(!0),this._socket.on("error",(e=>{this.#s=!1,this.#i=!1,this.#n.reconnect&&this.#l(),this.#g(o.InstanceStatus.UnknownError,e.message),this.emit("error",e)})),this._socket.on("ready",(()=>{this.#i=!0,this.#s=!1,this.#g(o.InstanceStatus.Ok),this.emit("connect")})),this._socket.on("end",(()=>{this.#i=!1,this.#g(o.InstanceStatus.Disconnected),!this.#s&&this.#n.reconnect&&this.#l(),this.emit("end")})),this._socket.on("data",(e=>this.emit("data",e))),this._socket.on("drain",(()=>this.emit("drain"))),setImmediate((()=>this.connect())),this.#c=setTimeout((()=>{this.#c=void 0,this.#o||this.listenerCount("error")||console.error(`Danger: TCP client for ${this.#e}:${this.#t} is missing an error handler!`)}),5e3)}connect(){if(this.#o)throw new Error("Cannot connect destroyed socket");return!this.#s&&(this.#s=!0,this._socket.connect(this.#t,this.#e),!0)}async send(e){if(this.#o||this._socket.destroyed)throw new Error("Cannot write to destroyed socket");if(!e||!e.length)throw new Error("No message to send");if(!this.#i)return!1;try{return new Promise(((t,n)=>{this._socket.write(e,(e=>{e?n(e):t(!0)}))}))}catch(e){this.#i=!1;const t=e instanceof Error?e:new Error(`${e}`);throw this.#g(o.InstanceStatus.UnknownError,t.message),this.emit("error",t),t}}destroy(){this.#o=!0,void 0!==this.#a&&(clearTimeout(this.#a),this.#a=void 0),void 0!==this.#c&&(clearTimeout(this.#c),this.#c=void 0),this._socket.removeAllListeners(),this.removeAllListeners(),this._socket.destroy()}#l(){void 0!==this.#a&&clearTimeout(this.#a),this.#a=setTimeout((()=>{this.#a=void 0,this.#g(o.InstanceStatus.Connecting),this.connect()}),this.#n.reconnect_interval)}#g(e,t){this.#r!=e&&(this.#r=e,this.emit("status_change",e,t))}}t.TCPHelper=r},1118:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TelnetHelper=void 0;const i=n(1635).__importDefault(n(228)),s=n(2203),o=n(8895);class r extends i.default{#d;#u;#c;get isConnected(){return this.#d.isConnected}get isConnecting(){return this.#d.isConnecting}get isDestroyed(){return this.#d.isDestroyed}constructor(e,t,n){super(),this.#d=new o.TCPHelper(e,t,n),this.#u=new a,this.#d._socket.pipe(this.#u),this.#d.on("connect",(()=>this.emit("connect"))),this.#d.on("end",(()=>this.emit("end"))),this.#d.on("error",(e=>this.emit("error",e))),this.#d.on("status_change",((e,t)=>this.emit("status_change",e,t))),this.#u.on("iac",((e,t)=>this.emit("iac",e,t))),this.#u.on("sb",(e=>this.emit("sb",e))),this.#u.on("data",(e=>this.emit("data",e))),this.#u.on("drain",(()=>this.emit("drain"))),this.#c=setTimeout((()=>{this.#c=void 0,this.isDestroyed||this.listenerCount("error")||console.error(`Danger: Telnet client for ${e}:${t} is missing an error handler!`)}),5e3)}connect(){return this.#d.connect()}async send(e){return this.#d.send(e)}destroy(){this.#d.destroy(),void 0!==this.#c&&(clearTimeout(this.#c),this.#c=void 0),this.#u.removeAllListeners(),this.#u.destroy()}}t.TelnetHelper=r;class a extends s.Transform{#b;#I;#p;constructor(e){super(e),this.#b=Buffer.alloc(0),this.#I=Buffer.alloc(0),this.#p=0}_transform(e,t,n){for(let t=0;t=251&&this.#p<=254){let t;switch(this.#p){case 251:t="WILL";break;case 252:t="WONT";break;case 253:t="DO";break;case 254:t="DONT";break;default:return}return this.emit("iac",t,e),void(this.#p=0)}if(250===this.#p){if(240===e)return this.emit("sb",this.#I),this.#p=0,void(this.#I=Buffer.alloc(0));this.#I=Buffer.concat([this.#I,Buffer.from([e])])}}}#h(){const e=this.#b;return this.#b=Buffer.alloc(0),e}}},6259:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.UDPHelper=void 0;const i=n(1635).__importDefault(n(7194)),s=n(228),o=n(1400);class r extends s.EventEmitter{#e;#t;#m;#n;#o=!1;#r;#c;get isDestroyed(){return this.#o}constructor(e,t,n){super(),this.#e=e,this.#t=t,this.#n={...n},this.#m=i.default.createSocket("udp4");try{this.#m.bind(this.#n.bind_port||0,this.#n.bind_ip)}catch(e){throw new Error(`Unable to bind to ip/port: ${this.#n.bind_ip}:${this.#n.bind_port}`)}this.#n.broadcast&&this.#m.setBroadcast(!0),void 0!==this.#n.ttl&&this.#m.setTTL(this.#n.ttl),void 0!==this.#n.multicast_ttl&&this.#m.setMulticastTTL(this.#n.multicast_ttl),this.#m.on("error",(e=>{this.#g(o.InstanceStatus.UnknownError,e.message),this.emit("error",e)})),this.#m.on("listening",(()=>{this.#n.multicast_interface&&this.#m.setMulticastInterface(this.#n.multicast_interface),this.#g(o.InstanceStatus.Ok),this.emit("listening")})),this.#m.on("message",(e=>this.emit("data",e))),this.#c=setTimeout((()=>{this.#o||this.listenerCount("error")||console.error(`Danger: UDP socket for ${this.#e}:${this.#t} is missing an error handler!`)}),5e3)}async send(e){if(this.#o)throw new Error("Cannot write to destroyed socket");if(!e||!e.length)throw new Error("No message to send");return new Promise(((t,n)=>{this.#m.send(e,this.#t,this.#e,(e=>{e?n(e):t()}))}))}destroy(){this.#o=!0,void 0!==this.#c&&(clearTimeout(this.#c),this.#c=void 0),this.#m.removeAllListeners(),this.#m.close(),this.removeAllListeners()}#g(e,t){this.#r!=e&&(this.#r=e,this.emit("status_change",e,t))}}t.UDPHelper=r},4044:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.IpcWrapper=void 0;const i=n(1635),s=n(360),o=i.__importDefault(n(6022));t.IpcWrapper=class{#y;#Z;#G;#B=1;#A=new Map;constructor(e,t,n){this.#y=e,this.#Z=t,this.#G=n}async sendWithCb(e,t,n,i=0){i<=0&&(i=this.#G);const s={timeout:void 0,resolve:()=>null,reject:()=>null},r=new Promise(((e,t)=>{s.resolve=e,s.reject=t}));this.#B>268435456&&(this.#B=1);const a=this.#B++;this.#A.set(a,s),this.#Z({direction:"call",name:String(e),payload:o.default.stringify(t),callbackId:a});const c=new Error("Call timed out");return s.timeout=setTimeout((()=>{s.reject(n?n():c),this.#A.delete(a)}),i),r}sendWithNoCb(e,t){this.#Z({direction:"call",name:String(e),payload:o.default.stringify(t),callbackId:void 0})}receivedMessage(e){const t=e;switch(e.direction){case"call":{const t=this.#y[e.name];if(!t)return void(e.callbackId&&this.#Z({direction:"response",callbackId:e.callbackId,success:!1,payload:o.default.stringify({message:`Unknown command "${e.name}"`})}));t(e.payload?o.default.parse(e.payload):void 0).then((t=>{e.callbackId&&this.#Z({direction:"response",callbackId:e.callbackId,success:!0,payload:o.default.stringify(t)})}),(t=>{e.callbackId&&this.#Z({direction:"response",callbackId:e.callbackId,success:!1,payload:t instanceof Error?JSON.stringify(t,Object.getOwnPropertyNames(t)):o.default.stringify(t)})}));break}case"response":{if(!e.callbackId)return void console.error("Ipc: Response message has no callbackId");const t=this.#A.get(e.callbackId);if(this.#A.delete(e.callbackId),!t)return;clearTimeout(t.timeout);const n=e.payload?o.default.parse(e.payload):void 0;if(e.success)t.resolve(n);else{let e=n;n&&"object"==typeof n&&"message"in n&&(e=new Error(n.message),n.stack&&(e.stack=n.stack)),t.reject(e)}break}default:(0,s.assertNever)(e),console.error(`Ipc: Message of unknown direction "${t.direction}"`)}}}},9967:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HostApiNodeJsIpc=void 0,t.HostApiNodeJsIpc="nodejs-ipc"},6278:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.runEntrypoint=t.assertNever=t.splitHex=t.splitHsv=t.splitHsl=t.splitRgb=t.combineRgb=t.literal=void 0;const i=n(1635);i.__exportStar(n(9077),t),i.__exportStar(n(2018),t),i.__exportStar(n(4581),t);var s=n(360);Object.defineProperty(t,"literal",{enumerable:!0,get:function(){return s.literal}}),Object.defineProperty(t,"combineRgb",{enumerable:!0,get:function(){return s.combineRgb}}),Object.defineProperty(t,"splitRgb",{enumerable:!0,get:function(){return s.splitRgb}}),Object.defineProperty(t,"splitHsl",{enumerable:!0,get:function(){return s.splitHsl}}),Object.defineProperty(t,"splitHsv",{enumerable:!0,get:function(){return s.splitHsv}}),Object.defineProperty(t,"splitHex",{enumerable:!0,get:function(){return s.splitHex}}),Object.defineProperty(t,"assertNever",{enumerable:!0,get:function(){return s.assertNever}}),i.__exportStar(n(6160),t);var o=n(4326);Object.defineProperty(t,"runEntrypoint",{enumerable:!0,get:function(){return o.runEntrypoint}})},4289:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ActionManager=void 0;const i=n(2593);function s(e){return{id:e.id,actionId:e.actionId,controlId:e.controlId,options:e.options}}t.ActionManager=class{#W;#f;#V;#v=new Map;#R=new Map;constructor(e,t,n){this.#W=e,this.#f=t,this.#V=n}async handleExecuteAction(e){const t=this.#v.get(e.action.actionId);if(!t)throw new Error(`Unknown action: ${e.action.actionId}`);const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.action.controlId,actionInstanceId:e.action.id,feedbackInstanceId:void 0})).text};await t.callback({id:e.action.id,actionId:e.action.actionId,controlId:e.action.controlId,options:e.action.options,surfaceId:e.surfaceId},n)}handleUpdateActions(e){for(const[t,n]of Object.entries(e)){const e=this.#R.get(t);if(e){const t=this.#v.get(e.actionId);if(t?.unsubscribe){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.controlId,actionInstanceId:e.id,feedbackInstanceId:void 0})).text};Promise.resolve(t.unsubscribe(s(e),n)).catch((t=>{this.#V("error",`Action unsubscribe failed: ${JSON.stringify(e)} - ${t?.message??t} ${t?.stack}`)}))}}if(!n||n.disabled)this.#R.delete(t);else{this.#R.set(t,n);const e=this.#v.get(n.actionId);if(e?.subscribe){const t={parseVariablesInString:async e=>(await this.#W({text:e,controlId:n.controlId,actionInstanceId:n.id,feedbackInstanceId:void 0})).text};Promise.resolve(e.subscribe(s(n),t)).catch((e=>{this.#V("error",`Action subscribe failed: ${JSON.stringify(n)} - ${e?.message??e} ${e?.stack}`)}))}}}}async handleLearnAction(e){const t=this.#v.get(e.action.actionId);if(t&&t.learn){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.action.controlId,actionInstanceId:e.action.id,feedbackInstanceId:void 0})).text};return{options:await t.learn({id:e.action.id,actionId:e.action.actionId,controlId:e.action.controlId,options:e.action.options,surfaceId:void 0},n)}}return{options:void 0}}setActionDefinitions(e){const t=[];this.#v.clear();for(const[n,s]of Object.entries(e))s&&(t.push({id:n,name:s.name,description:s.description,options:(0,i.serializeIsVisibleFn)(s.options),hasLearn:!!s.learn,learnTimeout:s.learnTimeout}),this.#v.set(n,s));this.#f({actions:t})}_getAllActions(){return Array.from(this.#R.values()).map((e=>({id:e.id,actionId:e.actionId,controlId:e.controlId,options:e.options})))}subscribeActions(e){let t=Array.from(this.#R.values());const n=new Set(e);n.size&&(t=t.filter((e=>n.has(e.actionId))));for(const e of t){const t=this.#v.get(e.actionId);if(t?.subscribe){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.controlId,actionInstanceId:e.id,feedbackInstanceId:void 0})).text};Promise.resolve(t.subscribe(s(e),n)).catch((t=>{this.#V("error",`Action subscribe failed: ${JSON.stringify(e)} - ${t?.message??t} ${t?.stack}`)}))}}}unsubscribeActions(e){let t=Array.from(this.#R.values());const n=new Set(e);n.size&&(t=t.filter((e=>n.has(e.actionId))));for(const e of t){const t=this.#v.get(e.actionId);if(t&&t.unsubscribe){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.controlId,actionInstanceId:e.id,feedbackInstanceId:void 0})).text};Promise.resolve(t.unsubscribe(s(e),n)).catch((t=>{this.#V("error",`Action unsubscribe failed: ${JSON.stringify(e)} - ${t?.message??t} ${t?.stack}`)}))}}}}},2593:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isInstanceBaseProps=t.serializeIsVisibleFn=void 0,t.serializeIsVisibleFn=function(e){return(e??[]).map((e=>"isVisible"in e&&"function"==typeof e.isVisible?{...e,isVisibleFn:e.isVisible.toString(),isVisible:void 0}:{...e,isVisibleFn:void 0}))},t.isInstanceBaseProps=function(e){const t=e;return"object"==typeof t&&"string"==typeof t.id&&!0===t._isInstanceBaseProps}},8039:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FeedbackManager=void 0;const i=n(1635),s=n(2593),o=i.__importDefault(n(7e3));function r(e,t){return{type:e,id:t.id,feedbackId:t.feedbackId,controlId:t.controlId,options:t.options}}t.FeedbackManager=class{#W;#Y;#X;#V;#H=new Map;#S=new Map;#N=new Map;#w=new Map;#K;get parseVariablesContext(){return this.#K}constructor(e,t,n,i){this.#W=e,this.#Y=t,this.#X=n,this.#V=i}getDefinitionIds(){return Array.from(this.#H.keys())}getInstanceIds(){return Array.from(this.#S.keys())}handleUpdateFeedbacks(e){for(const[t,n]of Object.entries(e)){const e=this.#S.get(t);if(e){const t=this.#H.get(e.feedbackId);if(t?.unsubscribe){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.controlId,actionInstanceId:void 0,feedbackInstanceId:e.id})).text};Promise.resolve(t.unsubscribe(r(t.type,e),n)).catch((t=>{this.#V("error",`Feedback unsubscribe failed: ${JSON.stringify(e)} - ${t?.message??t} ${t?.stack}`)}))}}if(!n||n.disabled)this.#S.delete(t);else{this.#S.set(t,{...n,referencedVariables:null});const e=this.#H.get(n.feedbackId);if(e?.subscribe){const t={parseVariablesInString:async e=>(await this.#W({text:e,controlId:n.controlId,actionInstanceId:void 0,feedbackInstanceId:n.id})).text};Promise.resolve(e.subscribe(r(e.type,n),t)).catch((e=>{this.#V("error",`Feedback subscribe failed: ${JSON.stringify(n)} - ${e?.message??e} ${e?.stack}`)}))}this.#F(t)}}}async handleLearnFeedback(e){const t=this.#H.get(e.feedback.feedbackId);if(t&&t.learn){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.feedback.controlId,actionInstanceId:void 0,feedbackInstanceId:e.feedback.id})).text};return{options:await t.learn({id:e.feedback.id,feedbackId:e.feedback.feedbackId,controlId:e.feedback.controlId,options:e.feedback.options,type:t.type},n)}}return{options:void 0}}handleVariablesChanged(e){if(!e.variablesIds.length)return;const t=new Set(e.variablesIds);for(const t of this.#w.values())for(const n of e.variablesIds)t.changedVariables.add(n);const n=new Set;for(const e of this.#S.values())if(!this.#w.has(e.id)&&e.referencedVariables)for(const i of e.referencedVariables)if(t.has(i)){n.add(e.id);break}for(const e of n)setImmediate((()=>{this.#F(e)}))}#F(e){const t=this.#w.get(e);if(t)return void(t.needsRecheck=!0);const n=this.#S.get(e);if(!n)return;const i=n,s={needsRecheck:!1,changedVariables:new Set};this.#w.set(e,s),Promise.resolve().then((async()=>{const t=this.#H.get(i.feedbackId);let n;const s=new Set;if(t){this.#K=`Feedback ${i.feedbackId} (${e})`;const o={parseVariablesInString:async t=>{const n=await this.#W({text:t,controlId:i.controlId,actionInstanceId:void 0,feedbackInstanceId:e});if(n.variableIds&&n.variableIds.length)for(const e of n.variableIds)s.add(e);return n.text}};n="boolean"===t.type?t.callback({...r("boolean",i),type:"boolean"},o):t.callback({...r("advanced",i),type:"advanced",image:i.image},o),this.#K=void 0}const o=await n;this.#N.set(e,{id:e,controlId:i.controlId,value:o}),this.#k(),i.referencedVariables=s.size>0?Array.from(s):null})).catch((e=>{console.error(`Feedback check failed: ${JSON.stringify(i)} - ${e?.message??e} ${e?.stack}`)})).finally((()=>{this.#K=void 0,this.#w.delete(e);let t=!1;if(i.referencedVariables)for(const e of i.referencedVariables)if(s.changedVariables.has(e)){t=!0;break}(t||s.needsRecheck)&&setImmediate((()=>{this.#F(e)}))}))}#k=(0,o.default)((()=>{const e=this.#N;this.#N=new Map,e.size>0&&this.#Y({values:Array.from(e.values())})}),{wait:5,maxWait:25});setFeedbackDefinitions(e){const t=[];this.#H.clear();for(const[n,i]of Object.entries(e))i&&(t.push({id:n,name:i.name,description:i.description,options:(0,s.serializeIsVisibleFn)(i.options),type:i.type,defaultStyle:"boolean"===i.type?i.defaultStyle:void 0,hasLearn:!!i.learn,learnTimeout:i.learnTimeout,showInvert:"boolean"===i.type&&i.showInvert}),this.#H.set(n,i));this.#X({feedbacks:t})}checkFeedbacks(e){const t=new Set(e);for(const[e,n]of this.#S.entries())this.#H.get(n.feedbackId)&&(0===t.size||t.has(n.feedbackId))&&this.#F(e)}checkFeedbacksById(e){for(const t of e)this.#F(t)}_getAllFeedbacks(){return Array.from(this.#S.values()).map((e=>({id:e.id,feedbackId:e.feedbackId,controlId:e.controlId,options:e.options})))}subscribeFeedbacks(e){let t=Array.from(this.#S.values());const n=new Set(e);n.size&&(t=t.filter((e=>n.has(e.feedbackId))));for(const e of t){const t=this.#H.get(e.feedbackId);if(t?.subscribe){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.controlId,actionInstanceId:void 0,feedbackInstanceId:e.id})).text};Promise.resolve(t.subscribe(r(t.type,e),n)).catch((t=>{this.#V("error",`Feedback subscribe failed: ${JSON.stringify(e)} - ${t?.message??t} ${t?.stack}`)}))}}}unsubscribeFeedbacks(e){let t=Array.from(this.#S.values());const n=new Set(e);n.size&&(t=t.filter((e=>n.has(e.feedbackId))));for(const e of t){const t=this.#H.get(e.feedbackId);if(t&&t.unsubscribe){const n={parseVariablesInString:async t=>(await this.#W({text:t,controlId:e.controlId,actionInstanceId:void 0,feedbackInstanceId:e.id})).text};Promise.resolve(t.unsubscribe(r(t.type,e),n)).catch((t=>{this.#V("error",`Feedback unsubscribe failed: ${JSON.stringify(e)} - ${t?.message??t} ${t?.stack}`)}))}}}}},1706:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.runThroughUpgradeScripts=void 0;const i=n(360);function s(e){return JSON.parse(JSON.stringify(e))}t.runThroughUpgradeScripts=function(e,t,n,o,r,a){const c=new Map,l=e=>{let t=c.get(e);return t||(t={actions:[],feedbacks:[],config:!1},c.set(e,t)),t};for(const t of Object.values(e)){const e=t?.upgradeIndex??n;t&&"number"==typeof e&&l(e).actions.push(t.id)}for(const e of Object.values(t)){const t=e?.upgradeIndex??n;e&&"number"==typeof t&&l(t).feedbacks.push(e.id)}if(!a)for(let e=n??-1;e0){const a=Array.from(c.keys()).sort(),l=Math.min(...a,n??-1)+1,b=[],I=[],p=o.length;for(let n=l;n{const n=e[t];if(n)return(0,i.literal)({id:n.id,controlId:n.controlId,actionId:n.actionId,options:void 0!==n.options?s(n.options):{}})})).filter((e=>!!e)),feedbacks:I.map((e=>{const n=t[e];if(n)return(0,i.literal)({id:n.id,controlId:n.controlId,feedbackId:n.feedbackId,options:void 0!==n.options?s(n.options):{},isInverted:n.isInverted})})).filter((e=>!!e))});l&&C.updatedConfig&&(u=C.updatedConfig);for(const t of C.updatedActions)if(t){const n=e[t.id];n&&(n.actionId=t.actionId,n.options=t.options,d[t.id]=n)}for(const e of C.updatedFeedbacks)if(e){const n=t[e.id];n&&(n.feedbackId=e.feedbackId,n.options=e.options,g[e.id]={...n,style:g[e.id]?.style??e.style,isInverted:e.isInverted??!1})}}for(const[t,n]of Object.entries(e))d[t]||"number"!=typeof n?.upgradeIndex||(d[t]=n);for(const[e,n]of Object.entries(t))g[e]||"number"!=typeof n?.upgradeIndex||(g[e]=n)}return{updatedActions:d,updatedFeedbacks:g,updatedConfig:u}}},9077:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.validateManifest=void 0;const i=n(1635).__importDefault(n(7281));t.validateManifest=function(e){const t=JSON.stringify(e);if(t.includes("companion-module-your-module-name"))throw new Error("Manifest incorrectly references template module 'companion-module-your-module-name'");if(t.includes("module-shortname"))throw new Error("Manifest incorrectly references template module 'module-shortname'");if(t.includes("A short one line description of your module"))throw new Error("Manifest incorrectly references template module 'A short one line description of your module'");if(t.includes("Your name"))throw new Error("Manifest incorrectly references template module 'Your name'");if(t.includes("Your email"))throw new Error("Manifest incorrectly references template module 'Your email'");if(t.includes("Your company"))throw new Error("Manifest incorrectly references template module 'Your company'");if(t.includes("Your product"))throw new Error("Manifest incorrectly references template module 'Your product'");if(!(0,i.default)(e)){const e=i.default.errors;if(!e)throw new Error("Manifest failed validation with unknown reason");throw new Error(`Manifest validation failed: ${JSON.stringify(e)}`)}}},3730:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},1649:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.InstanceBase=void 0;const i=n(1635),s=n(360),o=i.__importDefault(n(3290)),r=n(2593),a=n(1706),c=n(8039),l=n(4044),g=n(4289);t.InstanceBase=class{#_;#J;id;#z=new o.default({concurrency:1});#U=!1;#x=!1;#T={};#E;#L;#Q=new Map;#j=new Map;#n;#O;get instanceOptions(){return this.#n}get label(){return this.#O}constructor(e){if(!(0,r.isInstanceBaseProps)(e)||!e._isInstanceBaseProps)throw new Error("Module instance is being constructed incorrectly. Make sure you aren't trying to do this manually");this.#n={disableVariableValidation:!1},this.#_=new l.IpcWrapper({init:this._handleInit.bind(this),destroy:this._handleDestroy.bind(this),updateConfigAndLabel:this._handleConfigUpdateAndLabel.bind(this),updateConfig:async()=>{},executeAction:this._handleExecuteAction.bind(this),updateFeedbacks:this._handleUpdateFeedbacks.bind(this),updateActions:this._handleUpdateActions.bind(this),getConfigFields:this._handleGetConfigFields.bind(this),handleHttpRequest:this._handleHttpRequest.bind(this),learnAction:this._handleLearnAction.bind(this),learnFeedback:this._handleLearnFeedback.bind(this),startStopRecordActions:this._handleStartStopRecordActions.bind(this),variablesChanged:this._handleVariablesChanged.bind(this)},(e=>{process.send(e)}),5e3),process.on("message",(e=>{this.#_.receivedMessage(e)})),this.#E=new g.ActionManager((async e=>this.#_.sendWithCb("parseVariablesInString",e)),(e=>this.#_.sendWithNoCb("setActionDefinitions",e)),this.log.bind(this)),this.#L=new c.FeedbackManager((async e=>this.#_.sendWithCb("parseVariablesInString",e)),(e=>this.#_.sendWithNoCb("updateFeedbackValues",e)),(e=>this.#_.sendWithNoCb("setFeedbackDefinitions",e)),this.log.bind(this)),this.#J=e.upgradeScripts,this.id=e.id,this.#O=e.id,this.log("debug","Initializing")}async _handleInit(e){return this.#z.add((async()=>{if(this.#U)throw new Error("Already initialized");const t=e.actions,n=e.feedbacks;if(this.#T=e.config,this.#O=e.label,e.isFirstInit){const t={},n=this.getConfigFields();for(const e of n)"default"in e&&(t[e.id]=e.default);this.#T=t,this.saveConfig(this.#T),e.lastUpgradeIndex=this.#J.length-1}const{updatedActions:i,updatedFeedbacks:s,updatedConfig:o}=(0,a.runThroughUpgradeScripts)(t,n,e.lastUpgradeIndex,this.#J,this.#T,!1);this.#T=o??this.#T;const r=this.#_.sendWithCb("upgradedItems",{updatedActions:i,updatedFeedbacks:s});try{await this.init(this.#T,!!e.isFirstInit),this.#U=!0}catch(e){throw console.trace(`Init failed: ${e}`),e}finally{await r}return setImmediate((()=>{this._handleUpdateActions({actions:t},!0).catch((e=>{this.log("error",`Receive actions failed: ${e}`)})),this._handleUpdateFeedbacks({feedbacks:n},!0).catch((e=>{this.log("error",`Receive feedbacks failed: ${e}`)}))})),{hasHttpHandler:"function"==typeof this.handleHttpRequest,hasRecordActionsHandler:"function"==typeof this.handleStartStopRecordActions,newUpgradeIndex:this.#J.length-1,updatedConfig:this.#T}}))}async _handleDestroy(){await this.#z.add((async()=>{if(!this.#U)throw new Error("Not initialized");await this.destroy(),this.#U=!1}))}async _handleConfigUpdateAndLabel(e){await this.#z.add((async()=>{if(!this.#U)throw new Error("Not initialized");this.#O=e.label,this.#T=e.config,await this.configUpdated(this.#T)}))}async _handleExecuteAction(e){return this.#E.handleExecuteAction(e)}async _handleUpdateFeedbacks(e,t){if(!t){const t=(0,a.runThroughUpgradeScripts)({},e.feedbacks,null,this.#J,this.#T,!0);this.#_.sendWithCb("upgradedItems",{updatedActions:t.updatedActions,updatedFeedbacks:t.updatedFeedbacks}).catch((e=>{this.log("error",`Failed to save upgraded feedbacks: ${e}`)}))}this.#L.handleUpdateFeedbacks(e.feedbacks)}async _handleUpdateActions(e,t){if(!t){const t=(0,a.runThroughUpgradeScripts)(e.actions,{},null,this.#J,this.#T,!0);this.#_.sendWithCb("upgradedItems",{updatedActions:t.updatedActions,updatedFeedbacks:t.updatedFeedbacks}).catch((e=>{this.log("error",`Failed to save upgraded actions: ${e}`)}))}this.#E.handleUpdateActions(e.actions)}async _handleGetConfigFields(e){return{fields:(0,r.serializeIsVisibleFn)(this.getConfigFields())}}async _handleHttpRequest(e){if(!this.handleHttpRequest)throw new Error("handleHttpRequest is not supported!");return{response:await this.handleHttpRequest(e.request)}}async _handleLearnAction(e){return this.#E.handleLearnAction(e)}async _handleLearnFeedback(e){return this.#L.handleLearnFeedback(e)}async _handleStartStopRecordActions(e){if(e.recording){if(this.#x)return}else if(!this.#x)return;if(!this.handleStartStopRecordActions)throw this.#x=!1,new Error("Recording actions is not supported by this module!");this.#x=e.recording,this.handleStartStopRecordActions(this.#x)}async _handleVariablesChanged(e){this.#L.handleVariablesChanged(e)}saveConfig(e){this.#T=e,this.#_.sendWithNoCb("saveConfig",{config:e})}setActionDefinitions(e){this.#E.setActionDefinitions(e)}setFeedbackDefinitions(e){this.#L.setFeedbackDefinitions(e)}setPresetDefinitions(e){const t=[];for(const[n,i]of Object.entries(e))i&&t.push({...i,id:n});this.#_.sendWithNoCb("setPresetDefinitions",{presets:t})}setVariableDefinitions(e){const t=[],n=[];this.#Q.clear();for(const i of e)t.push({id:i.variableId,name:i.name}),this.#Q.set(i.variableId,i),this.#j.has(i.variableId)||(this.#j.set(i.variableId,""),n.push({id:i.variableId,value:""}));if(!this.#n.disableVariableValidation){const e=new Set(this.#Q.keys());for(const t of this.#j.keys())e.has(t)||(this.#j.delete(t),n.push({id:t,value:void 0}))}this.#_.sendWithNoCb("setVariableDefinitions",{variables:t,newValues:n})}setVariableValues(e){const t=[];for(const[n,i]of Object.entries(e))this.#n.disableVariableValidation?(void 0===i?this.#j.delete(n):this.#j.set(n,i),t.push({id:n,value:i})):this.#Q.has(n)?(this.#j.set(n,i??""),t.push({id:n,value:i??""})):t.push({id:n,value:void 0});this.#_.sendWithNoCb("setVariableValues",{newValues:t})}getVariableValue(e){return this.#j.get(e)}async parseVariablesInString(e){const t=this.#L.parseVariablesContext;return t&&this.log("debug",`parseVariablesInString called while in: ${t}. You should use the parseVariablesInString provided to the callback instead`),(await this.#_.sendWithCb("parseVariablesInString",{text:e,controlId:void 0,actionInstanceId:void 0,feedbackInstanceId:void 0})).text}checkFeedbacks(...e){this.#L.checkFeedbacks(e)}checkFeedbacksById(...e){this.#L.checkFeedbacksById(e)}_getAllActions(){return this.#E._getAllActions()}subscribeActions(...e){this.#E.subscribeActions(e)}unsubscribeActions(...e){this.#E.unsubscribeActions(e)}_getAllFeedbacks(){return this.#L._getAllFeedbacks()}subscribeFeedbacks(...e){this.#L.subscribeFeedbacks(e)}unsubscribeFeedbacks(...e){this.#L.unsubscribeFeedbacks(e)}recordAction(e,t){if(!this.#x)throw new Error("Not currently recording actions");this.#_.sendWithNoCb("recordAction",{uniquenessId:t??null,actionId:e.actionId,options:e.options})}setCustomVariableValue(e,t){this.#_.sendWithNoCb("setCustomVariable",{customVariableId:e,value:t})}oscSend(e,t,n,i){this.#_.sendWithNoCb("send-osc",(0,s.literal)({host:e,port:t,path:n,args:i}))}updateStatus(e,t){this.#_.sendWithNoCb("set-status",(0,s.literal)({status:e,message:t??null}))}log(e,t){this.#_.sendWithNoCb("log-message",(0,s.literal)({level:e,message:t}))}}},7386:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},1400:(e,t)=>{"use strict";var n,i;Object.defineProperty(t,"__esModule",{value:!0}),t.Regex=t.InstanceStatus=void 0,(i=t.InstanceStatus||(t.InstanceStatus={})).Ok="ok",i.Connecting="connecting",i.Disconnected="disconnected",i.ConnectionFailure="connection_failure",i.BadConfig="bad_config",i.UnknownError="unknown_error",i.UnknownWarning="unknown_warning",(n=t.Regex||(t.Regex={})).IP="/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/",n.HOSTNAME="/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/",n.BOOLEAN="/^(true|false|0|1)$/i",n.PORT="/^([1-9]|[1-8][0-9]|9[0-9]|[1-8][0-9]{2}|9[0-8][0-9]|99[0-9]|[1-8][0-9]{3}|9[0-8][0-9]{2}|99[0-8][0-9]|999[0-9]|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-4])$/",n.MAC_ADDRESS="/^(?:[a-fA-F0-9]{2}:){5}([a-fA-F0-9]{2})$/",n.PERCENT="/^(100|[0-9]|[0-9][0-9])$/",n.FLOAT="/^([0-9]*\\.)?[0-9]+$/",n.SIGNED_FLOAT="/^[+-]?([0-9]*\\.)?[0-9]+$/",n.FLOAT_OR_INT="/^([0-9]+)(\\.[0-9]+)?$/",n.NUMBER="/^\\d+$/",n.SIGNED_NUMBER="/^[+-]?\\d+$/",n.SOMETHING="/^.+$/",n.TIMECODE="/^(0*[0-9]|1[0-9]|2[0-4]):(0*[0-9]|[1-5][0-9]|60):(0*[0-9]|[1-5][0-9]|60):(0*[0-9]|[12][0-9]|30)$/"},8983:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},8104:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},2018:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=n(1635);i.__exportStar(n(3730),t),i.__exportStar(n(1649),t),i.__exportStar(n(7386),t),i.__exportStar(n(1400),t),i.__exportStar(n(8983),t),i.__exportStar(n(8104),t),i.__exportStar(n(3258),t),i.__exportStar(n(131),t),i.__exportStar(n(3371),t),i.__exportStar(n(9786),t),i.__exportStar(n(6132),t)},3258:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},131:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},3371:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},9786:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CreateUseBuiltinInvertForFeedbacksUpgradeScript=t.CreateConvertToBooleanFeedbackUpgradeScript=t.EmptyUpgradeScript=void 0,t.EmptyUpgradeScript=()=>({updatedConfig:null,updatedActions:[],updatedFeedbacks:[]}),t.CreateConvertToBooleanFeedbackUpgradeScript=function(e){return(t,n)=>{const i=[];for(const t of n.feedbacks){let n=e[t.feedbackId];if(!0===n&&(n={bg:"bgcolor",bgcolor:"bgcolor",fg:"color",color:"color",png64:"png64",png:"png64"}),n){t.style||(t.style={});for(const[e,s]of Object.entries(n))void 0!==t.options[e]&&(t.style[s]=t.options[e],delete t.options[e],i.push(t))}}return{updatedConfig:null,updatedActions:[],updatedFeedbacks:i}}},t.CreateUseBuiltinInvertForFeedbacksUpgradeScript=function(e){return(t,n)=>{const i=[];for(const t of n.feedbacks){const n=e[t.feedbackId];if("string"!=typeof n)continue;const s=t.options[n];void 0!==s&&(delete t.options[n],t.isInverted="true"===s||!0===s||Number(s)>0,i.push(t))}return{updatedConfig:null,updatedActions:[],updatedFeedbacks:i}}}},6132:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},360:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.splitHex=t.splitHsv=t.splitHsl=t.splitRgb=t.combineRgb=t.assertNever=t.literal=void 0;const i=n(6284);function s(e){if("number"==typeof e)return e>16777215?{r:e>>16&255,g:e>>8&255,b:255&e,a:(255-(e>>24&255))/255}:{r:e>>16&255,g:e>>8&255,b:255&e,a:1};if("string"==typeof e&&(0,i.colord)(e).isValid()){const t=(0,i.colord)(e).toRgb();return{r:t.r,g:t.g,b:t.b,a:t.a}}return{r:0,g:0,b:0,a:1}}t.literal=function(e){return e},t.assertNever=function(e){},t.combineRgb=function(e,t,n,i){let s=(255&e)<<16|(255&t)<<8|255&n;return i&&i>=0&&i<1&&(s+=16777216*Math.round(255*(1-i))),s},t.splitRgb=s,t.splitHsl=function(e){const t=s(e);return(0,i.colord)(`rgba(${t.r}, ${t.g}, ${t.b}, ${t.a})`).toHsl()},t.splitHsv=function(e){const t=s(e);return(0,i.colord)(`rgba(${t.r}, ${t.g}, ${t.b}, ${t.a})`).toHsv()},t.splitHex=function(e){const t=s(e);return(0,i.colord)(`rgba(${t.r}, ${t.g}, ${t.b}, ${t.a})`).toHex()}},7281:(e,t,n)=>{"use strict";e.exports=a,e.exports.default=a;const i={$schema:"http://json-schema.org/draft-07/schema#",type:"object",title:"ModuleManifest",properties:{$schema:{type:"string"},id:{type:"string",description:"Unique identifier for the module"},name:{type:"string",description:"Name of the module"},shortname:{type:"string"},description:{type:"string",description:"Description of the module "},version:{type:"string",description:"Current version of the module"},license:{type:"string",description:"SPDX identifier for license of the module"},repository:{type:"string",description:"URL to the source repository"},bugs:{type:"string",description:"URL to bug tracker"},maintainers:{type:"array",description:"List of active maintiners",uniqueItems:!0,items:{type:"object",title:"ModuleManifestMaintainer",properties:{name:{type:"string"},email:{type:"string"},github:{type:"string"}},required:["name"]}},legacyIds:{type:"array",description:"If the module had a different unique identifier previously, then specify it here",uniqueItems:!0,items:{type:"string"}},runtime:{type:"object",title:"ModuleManifestRuntime",description:"Information on how to execute the module",properties:{type:{type:"string",description:"Type of the module. Must be: node18"},api:{type:"string",description:"Which host-api does it use. In the future alternate options will be allowed",enum:["nodejs-ipc"]},apiVersion:{type:"string",description:"The version of the host-api used"},entrypoint:{type:"string",description:"Entrypoint to pass to the runtime. eg index.js"}},required:["type","api","apiVersion","entrypoint"]},manufacturer:{type:"string"},products:{type:"array",uniqueItems:!0,items:{type:"string"}},keywords:{type:"array",uniqueItems:!0,items:{type:"string"}},bonjourQueries:{type:"object",description:"If the device or software for your module supports bonjour announcements, Companion will offer an easy way to watch for these announcements.\nEach query you define must have a matching config field of type 'bonjour-device' with the same name",patternProperties:{"":{type:"object",title:"ModuleBonjourQuery",description:"",properties:{type:{type:"string"},protocol:{type:"string",enum:["tcp","udp"]},txt:{type:"object",description:"Match on any txt values returned in the query. This is useful to filter out devices of the same 'type' that are not supported",patternProperties:{"":{type:"string"}},additionalProperties:!1}},required:["type","protocol"],additionalProperties:!1}},additionalProperties:!1}},additionalProperties:!1,required:["id","name","shortname","description","version","license","repository","bugs","maintainers","legacyIds","runtime","manufacturer","products","keywords"]},s=Object.prototype.hasOwnProperty,o=n(7169).A,r=new RegExp("","u");function a(e,{instancePath:t="",parentData:n,parentDataProperty:c,rootData:l=e}={}){if(!e||"object"!=typeof e||Array.isArray(e))return a.errors=[{instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;{let n;if(void 0===e.id&&(n="id")||void 0===e.name&&(n="name")||void 0===e.shortname&&(n="shortname")||void 0===e.description&&(n="description")||void 0===e.version&&(n="version")||void 0===e.license&&(n="license")||void 0===e.repository&&(n="repository")||void 0===e.bugs&&(n="bugs")||void 0===e.maintainers&&(n="maintainers")||void 0===e.legacyIds&&(n="legacyIds")||void 0===e.runtime&&(n="runtime")||void 0===e.manufacturer&&(n="manufacturer")||void 0===e.products&&(n="products")||void 0===e.keywords&&(n="keywords"))return a.errors=[{instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:n},message:"must have required property '"+n+"'"}],!1;{const n=0;for(const n in e)if(!s.call(i.properties,n))return a.errors=[{instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:n},message:"must NOT have additional properties"}],!1;if(0===n){if(void 0!==e.$schema){const n=0;if("string"!=typeof e.$schema)return a.errors=[{instancePath:t+"/$schema",schemaPath:"#/properties/%24schema/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var g=0===n}else g=!0;if(g){if(void 0!==e.id){const n=0;if("string"!=typeof e.id)return a.errors=[{instancePath:t+"/id",schemaPath:"#/properties/id/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.name){const n=0;if("string"!=typeof e.name)return a.errors=[{instancePath:t+"/name",schemaPath:"#/properties/name/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.shortname){const n=0;if("string"!=typeof e.shortname)return a.errors=[{instancePath:t+"/shortname",schemaPath:"#/properties/shortname/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.description){const n=0;if("string"!=typeof e.description)return a.errors=[{instancePath:t+"/description",schemaPath:"#/properties/description/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.version){const n=0;if("string"!=typeof e.version)return a.errors=[{instancePath:t+"/version",schemaPath:"#/properties/version/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.license){const n=0;if("string"!=typeof e.license)return a.errors=[{instancePath:t+"/license",schemaPath:"#/properties/license/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.repository){const n=0;if("string"!=typeof e.repository)return a.errors=[{instancePath:t+"/repository",schemaPath:"#/properties/repository/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.bugs){const n=0;if("string"!=typeof e.bugs)return a.errors=[{instancePath:t+"/bugs",schemaPath:"#/properties/bugs/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.maintainers){let n=e.maintainers;const i=0;if(0===i){if(!Array.isArray(n))return a.errors=[{instancePath:t+"/maintainers",schemaPath:"#/properties/maintainers/type",keyword:"type",params:{type:"array"},message:"must be array"}],!1;{var d=!0;const e=n.length;for(let i=0;i1)for(;i--;)for(e=i;e--;)if(o(n[i],n[e]))return a.errors=[{instancePath:t+"/maintainers",schemaPath:"#/properties/maintainers/uniqueItems",keyword:"uniqueItems",params:{i,j:e},message:"must NOT have duplicate items (items ## "+e+" and "+i+" are identical)"}],!1}}}g=0===i}else g=!0;if(g){if(void 0!==e.legacyIds){let n=e.legacyIds;const i=0;if(0===i){if(!Array.isArray(n))return a.errors=[{instancePath:t+"/legacyIds",schemaPath:"#/properties/legacyIds/type",keyword:"type",params:{type:"array"},message:"must be array"}],!1;{var b=!0;const e=n.length;for(let i=0;i1){const s={};for(;i--;){let o=n[i];if("string"==typeof o){if("number"==typeof s[o])return e=s[o],a.errors=[{instancePath:t+"/legacyIds",schemaPath:"#/properties/legacyIds/uniqueItems",keyword:"uniqueItems",params:{i,j:e},message:"must NOT have duplicate items (items ## "+e+" and "+i+" are identical)"}],!1;s[o]=i}}}}}}g=0===i}else g=!0;if(g){if(void 0!==e.runtime){let n=e.runtime;const s=0;if(0===s){if(!n||"object"!=typeof n||Array.isArray(n))return a.errors=[{instancePath:t+"/runtime",schemaPath:"#/properties/runtime/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;{let e;if(void 0===n.type&&(e="type")||void 0===n.api&&(e="api")||void 0===n.apiVersion&&(e="apiVersion")||void 0===n.entrypoint&&(e="entrypoint"))return a.errors=[{instancePath:t+"/runtime",schemaPath:"#/properties/runtime/required",keyword:"required",params:{missingProperty:e},message:"must have required property '"+e+"'"}],!1;if(void 0!==n.type){const e=0;if("string"!=typeof n.type)return a.errors=[{instancePath:t+"/runtime/type",schemaPath:"#/properties/runtime/properties/type/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var I=0===e}else I=!0;if(I){if(void 0!==n.api){let e=n.api;const s=0;if("string"!=typeof e)return a.errors=[{instancePath:t+"/runtime/api",schemaPath:"#/properties/runtime/properties/api/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;if("nodejs-ipc"!==e)return a.errors=[{instancePath:t+"/runtime/api",schemaPath:"#/properties/runtime/properties/api/enum",keyword:"enum",params:{allowedValues:i.properties.runtime.properties.api.enum},message:"must be equal to one of the allowed values"}],!1;I=0===s}else I=!0;if(I){if(void 0!==n.apiVersion){const e=0;if("string"!=typeof n.apiVersion)return a.errors=[{instancePath:t+"/runtime/apiVersion",schemaPath:"#/properties/runtime/properties/apiVersion/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;I=0===e}else I=!0;if(I)if(void 0!==n.entrypoint){const e=0;if("string"!=typeof n.entrypoint)return a.errors=[{instancePath:t+"/runtime/entrypoint",schemaPath:"#/properties/runtime/properties/entrypoint/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;I=0===e}else I=!0}}}}g=0===s}else g=!0;if(g){if(void 0!==e.manufacturer){const n=0;if("string"!=typeof e.manufacturer)return a.errors=[{instancePath:t+"/manufacturer",schemaPath:"#/properties/manufacturer/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;g=0===n}else g=!0;if(g){if(void 0!==e.products){let n=e.products;const i=0;if(0===i){if(!Array.isArray(n))return a.errors=[{instancePath:t+"/products",schemaPath:"#/properties/products/type",keyword:"type",params:{type:"array"},message:"must be array"}],!1;{var p=!0;const e=n.length;for(let i=0;i1){const s={};for(;i--;){let o=n[i];if("string"==typeof o){if("number"==typeof s[o])return e=s[o],a.errors=[{instancePath:t+"/products",schemaPath:"#/properties/products/uniqueItems",keyword:"uniqueItems",params:{i,j:e},message:"must NOT have duplicate items (items ## "+e+" and "+i+" are identical)"}],!1;s[o]=i}}}}}}g=0===i}else g=!0;if(g){if(void 0!==e.keywords){let n=e.keywords;const i=0;if(0===i){if(!Array.isArray(n))return a.errors=[{instancePath:t+"/keywords",schemaPath:"#/properties/keywords/type",keyword:"type",params:{type:"array"},message:"must be array"}],!1;{var C=!0;const e=n.length;for(let i=0;i1){const s={};for(;i--;){let o=n[i];if("string"==typeof o){if("number"==typeof s[o])return e=s[o],a.errors=[{instancePath:t+"/keywords",schemaPath:"#/properties/keywords/uniqueItems",keyword:"uniqueItems",params:{i,j:e},message:"must NOT have duplicate items (items ## "+e+" and "+i+" are identical)"}],!1;s[o]=i}}}}}}g=0===i}else g=!0;if(g)if(void 0!==e.bonjourQueries){let n=e.bonjourQueries;const s=0;if(0===s){if(!n||"object"!=typeof n||Array.isArray(n))return a.errors=[{instancePath:t+"/bonjourQueries",schemaPath:"#/properties/bonjourQueries/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;{const e=0;for(const e in n)if(!r.test(e))return a.errors=[{instancePath:t+"/bonjourQueries",schemaPath:"#/properties/bonjourQueries/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:e},message:"must NOT have additional properties"}],!1;if(0===e)for(const e in n)if(r.test(e)){let s=n[e];const o=0;if(0===o){if(!s||"object"!=typeof s||Array.isArray(s))return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/bonjourQueries/patternProperties//type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;{let n;if(void 0===s.type&&(n="type")||void 0===s.protocol&&(n="protocol"))return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/bonjourQueries/patternProperties//required",keyword:"required",params:{missingProperty:n},message:"must have required property '"+n+"'"}],!1;{const n=0;for(const n in s)if("type"!==n&&"protocol"!==n&&"txt"!==n)return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/bonjourQueries/patternProperties//additionalProperties",keyword:"additionalProperties",params:{additionalProperty:n},message:"must NOT have additional properties"}],!1;if(0===n){if(void 0!==s.type){const n=0;if("string"!=typeof s.type)return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1")+"/type",schemaPath:"#/properties/bonjourQueries/patternProperties//properties/type/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var h=0===n}else h=!0;if(h){if(void 0!==s.protocol){let n=s.protocol;const o=0;if("string"!=typeof n)return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1")+"/protocol",schemaPath:"#/properties/bonjourQueries/patternProperties//properties/protocol/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;if("tcp"!==n&&"udp"!==n)return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1")+"/protocol",schemaPath:"#/properties/bonjourQueries/patternProperties//properties/protocol/enum",keyword:"enum",params:{allowedValues:i.properties.bonjourQueries.patternProperties[""].properties.protocol.enum},message:"must be equal to one of the allowed values"}],!1;h=0===o}else h=!0;if(h)if(void 0!==s.txt){let n=s.txt;const i=0;if(0===i){if(!n||"object"!=typeof n||Array.isArray(n))return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1")+"/txt",schemaPath:"#/properties/bonjourQueries/patternProperties//properties/txt/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;{const i=0;for(const i in n)if(!r.test(i))return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1")+"/txt",schemaPath:"#/properties/bonjourQueries/patternProperties//properties/txt/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:i},message:"must NOT have additional properties"}],!1;if(0===i)for(const i in n)if(r.test(i)){const s=0;if("string"!=typeof n[i])return a.errors=[{instancePath:t+"/bonjourQueries/"+e.replace(/~/g,"~0").replace(/\//g,"~1")+"/txt/"+i.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/bonjourQueries/patternProperties//properties/txt/patternProperties//type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;if(0!==s)break}}}h=0===i}else h=!0}}}}}if(0!==o)break}}}g=0===s}else g=!0}}}}}}}}}}}}}}}}}return a.errors=null,!0}},7e3:(e,t,n)=>{"use strict";const i=n(4865);e.exports=(e,t={})=>{if("function"!=typeof e)throw new TypeError(`Expected the first argument to be a function, got \`${typeof e}\``);const{wait:n=0,maxWait:s=0,before:o=!1,after:r=!0}=t;if(!o&&!r)throw new Error("Both `before` and `after` are false, function wouldn't be called.");let a,c,l;const g=function(...t){const i=this,g=o&&!a;return clearTimeout(a),a=setTimeout((()=>{a=void 0,c&&(clearTimeout(c),c=void 0),r&&(l=e.apply(i,t))}),n),s>0&&!c&&r&&(c=setTimeout((()=>{c=void 0,a&&(clearTimeout(a),a=void 0),l=e.apply(i,t)}),s)),g&&(l=e.apply(i,t)),l};return i(g,e),g.cancel=()=>{a&&(clearTimeout(a),a=void 0),c&&(clearTimeout(c),c=void 0)},g}},8515:(e,t,n)=>{"use strict";var i=n(6278);const s=[{id:"xvs-9000",label:"XVS 9000/8000/7000/6000"},{id:"xvs-g1",label:"XVS-G1"},{id:"mls-x1",label:"MLS-X1"}],o=[{id:"pp",label:"P/P",address:0},{id:"me1",label:"M/E 1",address:1},{id:"me2",label:"M/E 2",address:2},{id:"me3",label:"M/E 3",address:3},{id:"me4",label:"M/E 4",address:4},{id:"me5",label:"M/E 5",address:5}],r=[{id:"fm1",label:"FM1",address:20},{id:"fm2",label:"FM2",address:21}],a=[{id:"aux1",label:"Aux 1",address:48},{id:"aux2",label:"Aux 2",address:49},{id:"aux3",label:"Aux 3",address:50},{id:"aux4",label:"Aux 4",address:51},{id:"aux5",label:"Aux 5",address:52},{id:"aux6",label:"Aux 6",address:53},{id:"aux7",label:"Aux 7",address:54},{id:"aux8",label:"Aux 8",address:55},{id:"aux9",label:"Aux 9",address:56},{id:"aux10",label:"Aux 10",address:57},{id:"aux11",label:"Aux 11",address:58},{id:"aux12",label:"Aux 12",address:59},{id:"aux13",label:"Aux 13",address:60},{id:"aux14",label:"Aux 14",address:61},{id:"aux15",label:"Aux 15",address:62},{id:"aux16",label:"Aux 16",address:64},{id:"aux17",label:"Aux 17",address:65},{id:"aux18",label:"Aux 18",address:66},{id:"aux19",label:"Aux 19",address:67},{id:"aux20",label:"Aux 20",address:68},{id:"aux21",label:"Aux 21",address:69},{id:"aux22",label:"Aux 22",address:70},{id:"aux23",label:"Aux 23",address:71},{id:"aux24",label:"Aux 24",address:72},{id:"aux25",label:"Aux 25",address:73},{id:"aux26",label:"Aux 26",address:74},{id:"aux27",label:"Aux 27",address:75},{id:"aux28",label:"Aux 28",address:76},{id:"aux29",label:"Aux 29",address:77},{id:"aux30",label:"Aux 30",address:78},{id:"aux31",label:"Aux 31",address:79},{id:"aux32",label:"Aux 32",address:80},{id:"aux33",label:"Aux 33",address:81},{id:"aux34",label:"Aux 34",address:82},{id:"aux35",label:"Aux 35",address:83},{id:"aux36",label:"Aux 36",address:84},{id:"aux37",label:"Aux 37",address:85},{id:"aux38",label:"Aux 38",address:86},{id:"aux39",label:"Aux 39",address:87},{id:"aux40",label:"Aux 40",address:88},{id:"aux41",label:"Aux 41",address:89},{id:"aux42",label:"Aux 42",address:90},{id:"aux43",label:"Aux 43",address:91},{id:"aux44",label:"Aux 44",address:92},{id:"aux45",label:"Aux 45",address:93},{id:"aux46",label:"Aux 46",address:94},{id:"aux47",label:"Aux 47",address:95},{id:"aux48",label:"Aux 48",address:96},{id:"edit_pvw",label:"EDIT PVW",address:63}],c=[{id:"mp2_main",label:"MP2 Main, or Standard Config",writeByte:240,readByte:112},{id:"mp2_sub",label:"MP2 Sub",writeByte:241,readByte:113},{id:"mp2_both",label:"MP2 Main/Sub (Both)",writeByte:242,readByte:114}],l={"xvs-9000":[{id:"pgm",label:"PGM",readByte:64,writeByte:192},{id:"pst",label:"PST",readByte:65,writeByte:193},{id:"key1_fill",label:"Key 1 Fill",readByte:71,writeByte:199},{id:"key1_source",label:"Key 1 Source",readByte:72,writeByte:200},{id:"key2_fill",label:"Key 2 Fill",readByte:77,writeByte:205},{id:"key2_source",label:"Key 2 Source",readByte:78,writeByte:206},{id:"key3_fill",label:"Key 3 Fill",readByte:73,writeByte:201},{id:"key3_source",label:"Key 3 Source",readByte:74,writeByte:202},{id:"key4_fill",label:"Key 4 Fill",readByte:75,writeByte:203},{id:"key4_source",label:"Key 4 Source",readByte:76,writeByte:204},{id:"key5_fill",label:"Key 5 Fill",readByte:80,writeByte:208},{id:"key5_source",label:"Key 5 Source",readByte:81,writeByte:209},{id:"key6_fill",label:"Key 6 Fill",readByte:86,writeByte:214},{id:"key6_source",label:"Key 6 Source",readByte:87,writeByte:215},{id:"key7_fill",label:"Key 7 Fill",readByte:82,writeByte:210},{id:"key7_source",label:"Key 7 Source",readByte:83,writeByte:211},{id:"key8_fill",label:"Key 8 Fill",readByte:84,writeByte:212},{id:"key8_source",label:"Key 8 Source",readByte:85,writeByte:213},{id:"util1",label:"Utility 1",readByte:79,writeByte:207},{id:"util2",label:"Utility 2 / MP2 Sub BKGD A",readByte:66,writeByte:194},{id:"util3",label:"Utility 3 / MP2 Sub BKGD B",readByte:70,writeByte:198},{id:"dme_v",label:"DME V",readByte:67,writeByte:195},{id:"dme_k",label:"DME K",readByte:68,writeByte:196},{id:"dme_ext",label:"DME EXT",readByte:69,writeByte:197}],"xvs-g1":[{id:"pgm",label:"PGM",readByte:64,writeByte:192},{id:"pst",label:"PST",readByte:65,writeByte:193},{id:"key1_fill",label:"Key 1 Fill",readByte:71,writeByte:199},{id:"key1_source",label:"Key 1 Source",readByte:72,writeByte:200},{id:"key2_fill",label:"Key 2 Fill",readByte:77,writeByte:205},{id:"key2_source",label:"Key 2 Source",readByte:78,writeByte:206},{id:"key3_fill",label:"Key 3 Fill",readByte:73,writeByte:201},{id:"key3_source",label:"Key 3 Source",readByte:74,writeByte:202},{id:"key4_fill",label:"Key 4 Fill",readByte:75,writeByte:203},{id:"key4_source",label:"Key 4 Source",readByte:76,writeByte:204},{id:"key5_fill",label:"Key 5 Fill",readByte:80,writeByte:208},{id:"key5_source",label:"Key 5 Source",readByte:81,writeByte:209},{id:"key6_fill",label:"Key 6 Fill",readByte:86,writeByte:214},{id:"key6_source",label:"Key 6 Source",readByte:87,writeByte:215},{id:"key7_fill",label:"Key 7 Fill",readByte:82,writeByte:210},{id:"key7_source",label:"Key 7 Source",readByte:83,writeByte:211},{id:"key8_fill",label:"Key 8 Fill",readByte:84,writeByte:212},{id:"key8_source",label:"Key 8 Source",readByte:85,writeByte:213},{id:"util1",label:"Utility 1",readByte:79,writeByte:207},{id:"util2",label:"Utility 2",readByte:66,writeByte:194},{id:"mp2_sub_bkgd_a",label:"MP2 Sub BKGD A",readByte:88,writeByte:216},{id:"mp2_sub_bkgd_b",label:"MP2 Sub BKGD B",readByte:89,writeByte:217},{id:"mp2_sub_util2",label:"MP2 Sub UTILITY 2",readByte:70,writeByte:198},{id:"dme_v",label:"DME V",readByte:67,writeByte:195},{id:"dme_k",label:"DME K",readByte:68,writeByte:196},{id:"dme_ext",label:"DME EXT",readByte:69,writeByte:197}],"mls-x1":[{id:"pgm",label:"PGM",readByte:64,writeByte:192},{id:"pst",label:"PST",readByte:65,writeByte:193},{id:"key1_fill",label:"Key 1 Fill",readByte:71,writeByte:199},{id:"key1_source",label:"Key 1 Source",readByte:72,writeByte:200},{id:"key2_fill",label:"Key 2 Fill",readByte:77,writeByte:205},{id:"key2_source",label:"Key 2 Source",readByte:78,writeByte:206},{id:"key3_fill",label:"Key 3 Fill",readByte:73,writeByte:201},{id:"key3_source",label:"Key 3 Source",readByte:74,writeByte:202},{id:"key4_fill",label:"Key 4 Fill",readByte:75,writeByte:203},{id:"key4_source",label:"Key 4 Source",readByte:76,writeByte:204},{id:"key5_fill",label:"Key 5 Fill",readByte:80,writeByte:208},{id:"key5_source",label:"Key 5 Source",readByte:81,writeByte:209},{id:"key6_fill",label:"Key 6 Fill",readByte:86,writeByte:214},{id:"key6_source",label:"Key 6 Source",readByte:87,writeByte:215},{id:"key7_fill",label:"Key 7 Fill",readByte:82,writeByte:210},{id:"key7_source",label:"Key 7 Source",readByte:83,writeByte:211},{id:"key8_fill",label:"Key 8 Fill",readByte:84,writeByte:212},{id:"key8_source",label:"Key 8 Source",readByte:85,writeByte:213},{id:"util1",label:"Utility 1",readByte:79,writeByte:207},{id:"util2",label:"Utility 2",readByte:66,writeByte:194},{id:"mp2_sub_bkgd_a",label:"MP2 Sub BKGD A",readByte:88,writeByte:216},{id:"mp2_sub_bkgd_b",label:"MP2 Sub BKGD B",readByte:89,writeByte:217},{id:"mp2_sub_util2",label:"MP2 Sub UTILITY 2",readByte:70,writeByte:198},{id:"dme_v",label:"DME V",readByte:67,writeByte:195},{id:"dme_k",label:"DME K",readByte:68,writeByte:196},{id:"dme_ext",label:"DME EXT",readByte:69,writeByte:197}]},g=[{id:"key1",label:"Key 1",address:16},{id:"key2",label:"Key 2",address:48},{id:"key3",label:"Key 3",address:80},{id:"key4",label:"Key 4",address:112},{id:"key5",label:"Key 5",address:144},{id:"key6",label:"Key 6",address:176},{id:"key7",label:"Key 7",address:208},{id:"key8",label:"Key 8",address:240}],d={"xvs-9000":[{id:1,label:"Primary 1",byte1:0,byte2:1},{id:2,label:"Primary 2",byte1:0,byte2:2},{id:3,label:"Primary 3",byte1:0,byte2:3},{id:4,label:"Primary 4",byte1:0,byte2:4},{id:5,label:"Primary 5",byte1:0,byte2:5},{id:6,label:"Primary 6",byte1:0,byte2:6},{id:7,label:"Primary 7",byte1:0,byte2:7},{id:8,label:"Primary 8",byte1:0,byte2:8},{id:9,label:"Primary 9",byte1:0,byte2:9},{id:10,label:"Primary 10",byte1:0,byte2:10},{id:11,label:"Primary 11",byte1:0,byte2:11},{id:12,label:"Primary 12",byte1:0,byte2:12},{id:13,label:"Primary 13",byte1:0,byte2:13},{id:14,label:"Primary 14",byte1:0,byte2:14},{id:15,label:"Primary 15",byte1:0,byte2:15},{id:16,label:"Primary 16",byte1:0,byte2:16},{id:17,label:"Primary 17",byte1:0,byte2:17},{id:18,label:"Primary 18",byte1:0,byte2:18},{id:19,label:"Primary 19",byte1:0,byte2:19},{id:20,label:"Primary 20",byte1:0,byte2:20},{id:21,label:"Primary 21",byte1:0,byte2:21},{id:22,label:"Primary 22",byte1:0,byte2:22},{id:23,label:"Primary 23",byte1:0,byte2:23},{id:24,label:"Primary 24",byte1:0,byte2:24},{id:25,label:"Primary 25",byte1:0,byte2:25},{id:26,label:"Primary 26",byte1:0,byte2:26},{id:27,label:"Primary 27",byte1:0,byte2:27},{id:28,label:"Primary 28",byte1:0,byte2:28},{id:29,label:"Primary 29",byte1:0,byte2:29},{id:30,label:"Primary 30",byte1:0,byte2:30},{id:31,label:"Primary 31",byte1:0,byte2:31},{id:32,label:"Primary 32",byte1:0,byte2:32},{id:33,label:"Primary 33",byte1:0,byte2:33},{id:34,label:"Primary 34",byte1:0,byte2:34},{id:35,label:"Primary 35",byte1:0,byte2:35},{id:36,label:"Primary 36",byte1:0,byte2:36},{id:37,label:"Primary 37",byte1:0,byte2:37},{id:38,label:"Primary 38",byte1:0,byte2:38},{id:39,label:"Primary 39",byte1:0,byte2:39},{id:40,label:"Primary 40",byte1:0,byte2:40},{id:41,label:"Primary 41",byte1:0,byte2:41},{id:42,label:"Primary 42",byte1:0,byte2:42},{id:43,label:"Primary 43",byte1:0,byte2:43},{id:44,label:"Primary 44",byte1:0,byte2:44},{id:45,label:"Primary 45",byte1:0,byte2:45},{id:46,label:"Primary 46",byte1:0,byte2:46},{id:47,label:"Primary 47",byte1:0,byte2:47},{id:48,label:"Primary 48",byte1:0,byte2:48},{id:49,label:"Primary 49",byte1:0,byte2:49},{id:50,label:"Primary 50",byte1:0,byte2:50},{id:51,label:"Primary 51",byte1:0,byte2:51},{id:52,label:"Primary 52",byte1:0,byte2:52},{id:53,label:"Primary 53",byte1:0,byte2:53},{id:54,label:"Primary 54",byte1:0,byte2:54},{id:55,label:"Primary 55",byte1:0,byte2:55},{id:56,label:"Primary 56",byte1:0,byte2:56},{id:57,label:"Primary 57",byte1:0,byte2:57},{id:58,label:"Primary 58",byte1:0,byte2:58},{id:59,label:"Primary 59",byte1:0,byte2:59},{id:60,label:"Primary 60",byte1:0,byte2:60},{id:61,label:"Primary 61",byte1:0,byte2:61},{id:62,label:"Primary 62",byte1:0,byte2:62},{id:63,label:"Primary 63",byte1:0,byte2:63},{id:64,label:"Primary 64",byte1:0,byte2:64},{id:65,label:"Primary 65",byte1:0,byte2:65},{id:66,label:"Primary 66",byte1:0,byte2:66},{id:67,label:"Primary 67",byte1:0,byte2:67},{id:68,label:"Primary 68",byte1:0,byte2:68},{id:69,label:"Primary 69",byte1:0,byte2:69},{id:70,label:"Primary 70",byte1:0,byte2:70},{id:71,label:"Primary 71",byte1:0,byte2:71},{id:72,label:"Primary 72",byte1:0,byte2:72},{id:73,label:"Primary 73",byte1:0,byte2:73},{id:74,label:"Primary 74",byte1:0,byte2:74},{id:75,label:"Primary 75",byte1:0,byte2:75},{id:76,label:"Primary 76",byte1:0,byte2:76},{id:77,label:"Primary 77",byte1:0,byte2:77},{id:78,label:"Primary 78",byte1:0,byte2:78},{id:79,label:"Primary 79",byte1:0,byte2:79},{id:80,label:"Primary 80",byte1:0,byte2:80},{id:81,label:"Primary 81",byte1:0,byte2:81},{id:82,label:"Primary 82",byte1:0,byte2:82},{id:83,label:"Primary 83",byte1:0,byte2:83},{id:84,label:"Primary 84",byte1:0,byte2:84},{id:85,label:"Primary 85",byte1:0,byte2:85},{id:86,label:"Primary 86",byte1:0,byte2:86},{id:87,label:"Primary 87",byte1:0,byte2:87},{id:88,label:"Primary 88",byte1:0,byte2:88},{id:89,label:"Primary 89",byte1:0,byte2:89},{id:90,label:"Primary 90",byte1:0,byte2:90},{id:91,label:"Primary 91",byte1:0,byte2:91},{id:92,label:"Primary 92",byte1:0,byte2:92},{id:93,label:"Primary 93",byte1:0,byte2:93},{id:94,label:"Primary 94",byte1:0,byte2:94},{id:95,label:"Primary 95",byte1:0,byte2:95},{id:96,label:"Primary 96",byte1:0,byte2:96},{id:97,label:"Primary 97",byte1:0,byte2:97},{id:98,label:"Primary 98",byte1:0,byte2:98},{id:99,label:"Primary 99",byte1:0,byte2:99},{id:100,label:"Primary 100",byte1:0,byte2:100},{id:101,label:"Primary 101",byte1:0,byte2:101},{id:102,label:"Primary 102",byte1:0,byte2:102},{id:103,label:"Primary 103",byte1:0,byte2:103},{id:104,label:"Primary 104",byte1:0,byte2:104},{id:105,label:"Primary 105",byte1:0,byte2:105},{id:106,label:"Primary 106",byte1:0,byte2:106},{id:107,label:"Primary 107",byte1:0,byte2:107},{id:108,label:"Primary 108",byte1:0,byte2:108},{id:109,label:"Primary 109",byte1:0,byte2:109},{id:110,label:"Primary 110",byte1:0,byte2:110},{id:111,label:"Primary 111",byte1:0,byte2:111},{id:112,label:"Primary 112",byte1:0,byte2:112},{id:113,label:"Primary 113",byte1:0,byte2:113},{id:114,label:"Primary 114",byte1:0,byte2:114},{id:115,label:"Primary 115",byte1:0,byte2:115},{id:116,label:"Primary 116",byte1:0,byte2:116},{id:117,label:"Primary 117",byte1:0,byte2:117},{id:118,label:"Primary 118",byte1:0,byte2:118},{id:119,label:"Primary 119",byte1:0,byte2:119},{id:120,label:"Primary 120",byte1:0,byte2:120},{id:121,label:"Primary 121",byte1:0,byte2:121},{id:122,label:"Primary 122",byte1:0,byte2:122},{id:123,label:"Primary 123",byte1:0,byte2:123},{id:124,label:"Primary 124",byte1:0,byte2:124},{id:125,label:"Primary 125",byte1:0,byte2:125},{id:126,label:"Primary 126",byte1:0,byte2:126},{id:127,label:"Primary 127",byte1:0,byte2:127},{id:128,label:"Primary 128",byte1:0,byte2:128},{id:129,label:"Primary 129",byte1:0,byte2:129},{id:130,label:"Primary 130",byte1:0,byte2:130},{id:131,label:"Primary 131",byte1:0,byte2:131},{id:132,label:"Primary 132",byte1:0,byte2:132},{id:133,label:"Primary 133",byte1:0,byte2:133},{id:134,label:"Primary 134",byte1:0,byte2:134},{id:135,label:"Primary 135",byte1:0,byte2:135},{id:136,label:"Primary 136",byte1:0,byte2:136},{id:137,label:"Primary 137",byte1:0,byte2:137},{id:138,label:"Primary 138",byte1:0,byte2:138},{id:139,label:"Primary 139",byte1:0,byte2:139},{id:140,label:"Primary 140",byte1:0,byte2:140},{id:141,label:"Primary 141",byte1:0,byte2:141},{id:142,label:"Primary 142",byte1:0,byte2:142},{id:143,label:"Primary 143",byte1:0,byte2:143},{id:144,label:"Primary 144",byte1:0,byte2:144},{id:145,label:"Primary 145",byte1:0,byte2:145},{id:146,label:"Primary 146",byte1:0,byte2:146},{id:147,label:"Primary 147",byte1:0,byte2:147},{id:148,label:"Primary 148",byte1:0,byte2:148},{id:149,label:"Primary 149",byte1:0,byte2:149},{id:150,label:"Primary 150",byte1:0,byte2:150},{id:151,label:"Primary 151",byte1:0,byte2:151},{id:152,label:"Primary 152",byte1:0,byte2:152},{id:153,label:"Primary 153",byte1:0,byte2:153},{id:154,label:"Primary 154",byte1:0,byte2:154},{id:155,label:"Primary 155",byte1:0,byte2:155},{id:156,label:"Primary 156",byte1:0,byte2:156},{id:157,label:"Primary 157",byte1:0,byte2:157},{id:158,label:"Primary 158",byte1:0,byte2:158},{id:159,label:"Primary 159",byte1:0,byte2:159},{id:160,label:"Primary 160",byte1:0,byte2:160},{id:165,label:"FC1",byte1:0,byte2:165},{id:166,label:"FC2",byte1:0,byte2:166},{id:167,label:"FC3",byte1:0,byte2:167},{id:168,label:"FC4",byte1:0,byte2:168},{id:169,label:"FC5",byte1:0,byte2:169},{id:170,label:"FC6",byte1:0,byte2:170},{id:171,label:"FC7",byte1:0,byte2:171},{id:172,label:"FC8",byte1:0,byte2:172},{id:173,label:"FC9",byte1:0,byte2:173},{id:174,label:"FC10",byte1:0,byte2:174},{id:175,label:"FC11",byte1:0,byte2:175},{id:176,label:"FC12",byte1:0,byte2:176},{id:177,label:"FC13",byte1:0,byte2:177},{id:178,label:"FC14",byte1:0,byte2:178},{id:179,label:"FC15",byte1:0,byte2:179},{id:180,label:"FC16",byte1:0,byte2:180},{id:181,label:"Black",byte1:0,byte2:181},{id:182,label:"White",byte1:0,byte2:182},{id:183,label:"Color Bkgd 1",byte1:0,byte2:183},{id:184,label:"Color Bkgd1-2",byte1:0,byte2:184},{id:185,label:"Color Bkgd 2",byte1:0,byte2:185},{id:186,label:"Color Bkgd2-2",byte1:0,byte2:186},{id:187,label:"FM1",byte1:0,byte2:187},{id:188,label:"FM2",byte1:0,byte2:188},{id:189,label:"FM3",byte1:0,byte2:189},{id:190,label:"FM4",byte1:0,byte2:190},{id:191,label:"FM5",byte1:0,byte2:191},{id:192,label:"FM6",byte1:0,byte2:192},{id:193,label:"FM7",byte1:0,byte2:193},{id:194,label:"FM8",byte1:0,byte2:194},{id:195,label:"FM9",byte1:0,byte2:195},{id:196,label:"FM10",byte1:0,byte2:196},{id:197,label:"FM11",byte1:0,byte2:197},{id:198,label:"FM12",byte1:0,byte2:198},{id:199,label:"FM13",byte1:0,byte2:199},{id:200,label:"FM14",byte1:0,byte2:200},{id:201,label:"FM15",byte1:0,byte2:201},{id:202,label:"FM16",byte1:0,byte2:202},{id:203,label:"FM17",byte1:0,byte2:203},{id:204,label:"FM18",byte1:0,byte2:204},{id:205,label:"FM19",byte1:0,byte2:205},{id:206,label:"FM20",byte1:0,byte2:206},{id:207,label:"CCR1",byte1:0,byte2:207},{id:208,label:"CCR2",byte1:0,byte2:208},{id:209,label:"CCR3",byte1:0,byte2:209},{id:210,label:"CCR4",byte1:0,byte2:210},{id:211,label:"DME MONV",byte1:0,byte2:211},{id:212,label:"DME MONK",byte1:0,byte2:212},{id:215,label:"ME1 Out 1",byte1:0,byte2:215},{id:216,label:"ME1 Out 2",byte1:0,byte2:216},{id:217,label:"ME1 Out 3",byte1:0,byte2:217},{id:218,label:"ME1 Out 4",byte1:0,byte2:218},{id:219,label:"ME1 Out 5",byte1:0,byte2:219},{id:220,label:"ME1 Out 6",byte1:0,byte2:220},{id:221,label:"ME 1 Out 7",byte1:0,byte2:221},{id:222,label:"ME 1 Out 8",byte1:0,byte2:222},{id:223,label:"ME 1 Out 9",byte1:0,byte2:223},{id:224,label:"ME 1 Out 10",byte1:0,byte2:224},{id:225,label:"ME 1 Out 11",byte1:0,byte2:225},{id:226,label:"ME 1 Out 12",byte1:0,byte2:226},{id:227,label:"ME 1 ProcV",byte1:0,byte2:227},{id:228,label:"ME 1 ProcV-2",byte1:0,byte2:228},{id:229,label:"ME 1 ProcK",byte1:0,byte2:229},{id:230,label:"ME 1 ProcK-2",byte1:0,byte2:230},{id:231,label:"ME 2 Out 1",byte1:0,byte2:231},{id:232,label:"ME 2 Out 2",byte1:0,byte2:232},{id:233,label:"ME 2 Out 3",byte1:0,byte2:232},{id:234,label:"ME 2 Out 4",byte1:0,byte2:234},{id:235,label:"ME 2 Out 5",byte1:0,byte2:235},{id:236,label:"ME 2 Out 6",byte1:0,byte2:236},{id:237,label:"ME 2 Out 7",byte1:0,byte2:237},{id:238,label:"ME 2 Out 8",byte1:0,byte2:238},{id:239,label:"ME 2 Out 9",byte1:0,byte2:239},{id:240,label:"ME 2 Out 10",byte1:0,byte2:240},{id:241,label:"ME 2 Out 11",byte1:0,byte2:241},{id:242,label:"ME 2 Out 12",byte1:0,byte2:242},{id:243,label:"ME 2 ProcV",byte1:0,byte2:243},{id:244,label:"ME 2 ProcV-2",byte1:0,byte2:244},{id:245,label:"ME 2 ProcK",byte1:0,byte2:245},{id:246,label:"ME 2 ProcK-2",byte1:0,byte2:246},{id:247,label:"ME 3 Out 1",byte1:0,byte2:247},{id:248,label:"ME 3 Out 2",byte1:0,byte2:248},{id:249,label:"ME 3 Out 3",byte1:0,byte2:249},{id:250,label:"ME 3 Out 4",byte1:0,byte2:250},{id:251,label:"ME 3 Out 5",byte1:0,byte2:251},{id:252,label:"ME 3 Out 6",byte1:0,byte2:252},{id:253,label:"ME 3 Out 7",byte1:0,byte2:253},{id:254,label:"ME 3 Out 8",byte1:0,byte2:254},{id:255,label:"ME 3 Out 9",byte1:0,byte2:255},{id:256,label:"ME 3 Out 10",byte1:1,byte2:0},{id:257,label:"ME 3 Out 11",byte1:1,byte2:1},{id:258,label:"ME 3 Out 12",byte1:1,byte2:2},{id:259,label:"ME 3 ProcV",byte1:1,byte2:3},{id:260,label:"ME 3 ProcV-2",byte1:1,byte2:4},{id:261,label:"ME 3 ProcK",byte1:1,byte2:5},{id:262,label:"ME 3 ProcK-2",byte1:1,byte2:6},{id:263,label:"ME 4 Out 1",byte1:1,byte2:7},{id:264,label:"ME 4 Out 2",byte1:1,byte2:8},{id:265,label:"ME 4 Out 3",byte1:1,byte2:9},{id:266,label:"ME 4 Out 4",byte1:1,byte2:10},{id:267,label:"ME 4 Out 5",byte1:1,byte2:11},{id:268,label:"ME 4 Out 6",byte1:1,byte2:12},{id:269,label:"ME 4 Out 7",byte1:1,byte2:13},{id:270,label:"ME 4 Out 8",byte1:1,byte2:14},{id:271,label:"ME 4 Out 9",byte1:1,byte2:15},{id:272,label:"ME 4 Out 10",byte1:1,byte2:16},{id:273,label:"ME 4 Out 11",byte1:1,byte2:17},{id:274,label:"ME 4 Out 12",byte1:1,byte2:18},{id:275,label:"ME 4 ProcV",byte1:1,byte2:19},{id:276,label:"ME 4 ProcV-2",byte1:1,byte2:20},{id:277,label:"ME 4 ProcK",byte1:1,byte2:21},{id:278,label:"ME 4 ProcK-2",byte1:1,byte2:22},{id:279,label:"ME 5 Out 1",byte1:1,byte2:23},{id:280,label:"ME 5 Out 2",byte1:1,byte2:24},{id:281,label:"ME 5 Out 3",byte1:1,byte2:25},{id:282,label:"ME 5 Out 4",byte1:1,byte2:26},{id:283,label:"ME 5 Out 5",byte1:1,byte2:27},{id:284,label:"ME 5 Out 6",byte1:1,byte2:28},{id:285,label:"ME 5 Out 7",byte1:1,byte2:29},{id:286,label:"ME 5 Out 8",byte1:1,byte2:30},{id:287,label:"ME 5 Out 9",byte1:1,byte2:31},{id:288,label:"ME 5 Out 10",byte1:1,byte2:32},{id:289,label:"ME 5 Out 11",byte1:1,byte2:33},{id:290,label:"ME 5 Out 12",byte1:1,byte2:34},{id:291,label:"ME 5 ProcV",byte1:1,byte2:35},{id:292,label:"ME 5 ProcV-2",byte1:1,byte2:36},{id:293,label:"ME 5 ProcK",byte1:1,byte2:37},{id:294,label:"ME 5 ProcK-2",byte1:1,byte2:38},{id:295,label:"P/P Out 1",byte1:1,byte2:39},{id:296,label:"P/P Out 2",byte1:1,byte2:40},{id:297,label:"P/P Out 3",byte1:1,byte2:41},{id:298,label:"P/P Out 4",byte1:1,byte2:42},{id:299,label:"P/P Out 5",byte1:1,byte2:43},{id:300,label:"P/P Out 6",byte1:1,byte2:44},{id:301,label:"P/P Out 7",byte1:1,byte2:45},{id:302,label:"P/P Out 8",byte1:1,byte2:46},{id:303,label:"P/P Out 9",byte1:1,byte2:47},{id:304,label:"P/P Out 10",byte1:1,byte2:48},{id:305,label:"P/P Out 11",byte1:1,byte2:49},{id:306,label:"P/P Out 12",byte1:1,byte2:50},{id:307,label:"P/P ProcV",byte1:1,byte2:51},{id:308,label:"P/P ProcV-2",byte1:1,byte2:52},{id:309,label:"P/P ProcK",byte1:1,byte2:53},{id:310,label:"P/P ProcK-2",byte1:1,byte2:54}],"xvs-g1":[{id:1,label:"Primary 1",byte1:0,byte2:1},{id:2,label:"Primary 2",byte1:0,byte2:2},{id:3,label:"Primary 3",byte1:0,byte2:3},{id:4,label:"Primary 4",byte1:0,byte2:4},{id:5,label:"Primary 5",byte1:0,byte2:5},{id:6,label:"Primary 6",byte1:0,byte2:6},{id:7,label:"Primary 7",byte1:0,byte2:7},{id:8,label:"Primary 8",byte1:0,byte2:8},{id:9,label:"Primary 9",byte1:0,byte2:9},{id:10,label:"Primary 10",byte1:0,byte2:10},{id:11,label:"Primary 11",byte1:0,byte2:11},{id:12,label:"Primary 12",byte1:0,byte2:12},{id:13,label:"Primary 13",byte1:0,byte2:13},{id:14,label:"Primary 14",byte1:0,byte2:14},{id:15,label:"Primary 15",byte1:0,byte2:15},{id:16,label:"Primary 16",byte1:0,byte2:16},{id:17,label:"Primary 17",byte1:0,byte2:17},{id:18,label:"Primary 18",byte1:0,byte2:18},{id:19,label:"Primary 19",byte1:0,byte2:19},{id:20,label:"Primary 20",byte1:0,byte2:20},{id:21,label:"Primary 21",byte1:0,byte2:21},{id:22,label:"Primary 22",byte1:0,byte2:22},{id:23,label:"Primary 23",byte1:0,byte2:23},{id:24,label:"Primary 24",byte1:0,byte2:24},{id:25,label:"Primary 25",byte1:0,byte2:25},{id:26,label:"Primary 26",byte1:0,byte2:26},{id:27,label:"Primary 27",byte1:0,byte2:27},{id:28,label:"Primary 28",byte1:0,byte2:28},{id:29,label:"Primary 29",byte1:0,byte2:29},{id:30,label:"Primary 30",byte1:0,byte2:30},{id:31,label:"Primary 31",byte1:0,byte2:31},{id:32,label:"Primary 32",byte1:0,byte2:32},{id:33,label:"Primary 33",byte1:0,byte2:33},{id:34,label:"Primary 34",byte1:0,byte2:34},{id:35,label:"Primary 35",byte1:0,byte2:35},{id:36,label:"Primary 36",byte1:0,byte2:36},{id:37,label:"Primary 37",byte1:0,byte2:37},{id:38,label:"Primary 38",byte1:0,byte2:38},{id:39,label:"Primary 39",byte1:0,byte2:39},{id:40,label:"Primary 40",byte1:0,byte2:40},{id:41,label:"Primary 41",byte1:0,byte2:41},{id:42,label:"Primary 42",byte1:0,byte2:42},{id:43,label:"Primary 43",byte1:0,byte2:43},{id:44,label:"Primary 44",byte1:0,byte2:44},{id:45,label:"Primary 45",byte1:0,byte2:45},{id:46,label:"Primary 46",byte1:0,byte2:46},{id:47,label:"Primary 47",byte1:0,byte2:47},{id:48,label:"Primary 48",byte1:0,byte2:48},{id:181,label:"Black",byte1:0,byte2:181},{id:182,label:"White",byte1:0,byte2:182},{id:183,label:"Color Bkgd 1",byte1:0,byte2:183},{id:185,label:"Color Bkgd 2",byte1:0,byte2:185},{id:187,label:"FM1",byte1:0,byte2:187},{id:188,label:"FM2",byte1:0,byte2:188},{id:189,label:"FM3",byte1:0,byte2:189},{id:190,label:"FM4",byte1:0,byte2:190},{id:191,label:"FM5",byte1:0,byte2:191},{id:192,label:"FM6",byte1:0,byte2:192},{id:193,label:"FM7",byte1:0,byte2:193},{id:194,label:"FM8",byte1:0,byte2:194},{id:195,label:"FM9",byte1:0,byte2:195},{id:196,label:"FM10",byte1:0,byte2:196},{id:197,label:"FM11",byte1:0,byte2:197},{id:198,label:"FM12",byte1:0,byte2:198},{id:199,label:"FM13",byte1:0,byte2:199},{id:200,label:"FM14",byte1:0,byte2:200},{id:201,label:"FM15",byte1:0,byte2:201},{id:202,label:"FM16",byte1:0,byte2:202},{id:203,label:"CLIP1",byte1:0,byte2:203},{id:204,label:"CLIP2",byte1:0,byte2:204},{id:205,label:"CLIP3",byte1:0,byte2:205},{id:206,label:"CLIP4",byte1:0,byte2:206},{id:207,label:"(DME MON3 V)",byte1:0,byte2:207},{id:208,label:"(DME MON3 K)",byte1:0,byte2:208},{id:209,label:"(DME MON4 V)",byte1:0,byte2:209},{id:210,label:"(DME MON4 K)",byte1:0,byte2:210},{id:211,label:"DME MON1 V",byte1:0,byte2:211},{id:212,label:"DME MON1 K",byte1:0,byte2:212},{id:213,label:"(DME MON2 V)",byte1:0,byte2:213},{id:214,label:"(DME MON2 K)",byte1:0,byte2:214},{id:215,label:"ME1 Out 1",byte1:0,byte2:215},{id:216,label:"ME1 Out 2",byte1:0,byte2:216},{id:217,label:"ME1 Out 3",byte1:0,byte2:217},{id:218,label:"ME1 Out 4",byte1:0,byte2:218},{id:219,label:"ME1 Out 5",byte1:0,byte2:219},{id:220,label:"ME1 Out 6",byte1:0,byte2:220},{id:221,label:"ME 1 Out 7",byte1:0,byte2:221},{id:222,label:"ME 1 Out 8",byte1:0,byte2:222},{id:231,label:"ME 2 Out 1",byte1:0,byte2:231},{id:232,label:"ME 2 Out 2",byte1:0,byte2:232},{id:233,label:"ME 2 Out 3",byte1:0,byte2:233},{id:234,label:"ME 2 Out 4",byte1:0,byte2:234},{id:235,label:"ME 2 Out 5",byte1:0,byte2:235},{id:236,label:"ME 2 Out 6",byte1:0,byte2:236},{id:237,label:"ME 2 Out 7",byte1:0,byte2:237},{id:238,label:"ME 2 Out 8",byte1:0,byte2:238},{id:247,label:"ME 3 Out 1",byte1:0,byte2:247},{id:248,label:"ME 3 Out 2",byte1:0,byte2:248},{id:249,label:"ME 3 Out 3",byte1:0,byte2:249},{id:250,label:"ME 3 Out 4",byte1:0,byte2:250},{id:251,label:"ME 3 Out 5",byte1:0,byte2:251},{id:252,label:"ME 3 Out 6",byte1:0,byte2:252},{id:253,label:"ME 3 Out 7",byte1:0,byte2:253},{id:254,label:"ME 3 Out 8",byte1:0,byte2:254},{id:263,label:"ME 4 Out 1",byte1:1,byte2:7},{id:264,label:"ME 4 Out 2",byte1:1,byte2:8},{id:265,label:"ME 4 Out 3",byte1:1,byte2:9},{id:266,label:"ME 4 Out 4",byte1:1,byte2:10},{id:267,label:"ME 4 Out 5",byte1:1,byte2:11},{id:268,label:"ME 4 Out 6",byte1:1,byte2:12},{id:269,label:"ME 4 Out 7",byte1:1,byte2:13},{id:270,label:"ME 4 Out 8",byte1:1,byte2:14},{id:279,label:"ME 5 Out 1",byte1:1,byte2:23},{id:280,label:"ME 5 Out 2",byte1:1,byte2:24},{id:281,label:"ME 5 Out 3",byte1:1,byte2:25},{id:282,label:"ME 5 Out 4",byte1:1,byte2:26},{id:283,label:"ME 5 Out 5",byte1:1,byte2:27},{id:284,label:"ME 5 Out 6",byte1:1,byte2:28},{id:285,label:"ME 5 Out 7",byte1:1,byte2:29},{id:286,label:"ME 5 Out 8",byte1:1,byte2:30},{id:295,label:"P/P Out 1",byte1:1,byte2:39},{id:296,label:"P/P Out 2",byte1:1,byte2:40},{id:297,label:"P/P Out 3",byte1:1,byte2:41},{id:298,label:"P/P Out 4",byte1:1,byte2:42},{id:299,label:"P/P Out 5",byte1:1,byte2:43},{id:300,label:"P/P Out 6",byte1:1,byte2:44},{id:301,label:"P/P Out 7",byte1:1,byte2:45},{id:302,label:"P/P Out 8",byte1:1,byte2:46}],"mls-x1":[{id:1,label:"Primary 1",byte1:0,byte2:1},{id:2,label:"Primary 2",byte1:0,byte2:2},{id:3,label:"Primary 3",byte1:0,byte2:3},{id:4,label:"Primary 4",byte1:0,byte2:4},{id:5,label:"Primary 5",byte1:0,byte2:5},{id:6,label:"Primary 6",byte1:0,byte2:6},{id:7,label:"Primary 7",byte1:0,byte2:7},{id:8,label:"Primary 8",byte1:0,byte2:8},{id:9,label:"Primary 9",byte1:0,byte2:9},{id:10,label:"Primary 10",byte1:0,byte2:10},{id:11,label:"Primary 11",byte1:0,byte2:11},{id:12,label:"Primary 12",byte1:0,byte2:12},{id:13,label:"Primary 13",byte1:0,byte2:13},{id:14,label:"Primary 14",byte1:0,byte2:14},{id:15,label:"Primary 15",byte1:0,byte2:15},{id:16,label:"Primary 16",byte1:0,byte2:16},{id:17,label:"Primary 17",byte1:0,byte2:17},{id:18,label:"Primary 18",byte1:0,byte2:18},{id:19,label:"Primary 19",byte1:0,byte2:19},{id:20,label:"Primary 20",byte1:0,byte2:20},{id:21,label:"Primary 21",byte1:0,byte2:21},{id:22,label:"Primary 22",byte1:0,byte2:22},{id:23,label:"Primary 23",byte1:0,byte2:23},{id:24,label:"Primary 24",byte1:0,byte2:24},{id:25,label:"Primary 25",byte1:0,byte2:25},{id:26,label:"Primary 26",byte1:0,byte2:26},{id:27,label:"Primary 27",byte1:0,byte2:27},{id:28,label:"Primary 28",byte1:0,byte2:28},{id:29,label:"Primary 29",byte1:0,byte2:29},{id:30,label:"Primary 30",byte1:0,byte2:30},{id:31,label:"Primary 31",byte1:0,byte2:31},{id:32,label:"Primary 32",byte1:0,byte2:32},{id:33,label:"Primary 33",byte1:0,byte2:33},{id:34,label:"Primary 34",byte1:0,byte2:34},{id:35,label:"Primary 35",byte1:0,byte2:35},{id:36,label:"Primary 36",byte1:0,byte2:36},{id:37,label:"Primary 37",byte1:0,byte2:37},{id:38,label:"Primary 38",byte1:0,byte2:38},{id:39,label:"Primary 39",byte1:0,byte2:39},{id:40,label:"Primary 40",byte1:0,byte2:40},{id:41,label:"Primary 41",byte1:0,byte2:41},{id:42,label:"Primary 42",byte1:0,byte2:42},{id:43,label:"Primary 43",byte1:0,byte2:43},{id:44,label:"Primary 44",byte1:0,byte2:44},{id:45,label:"Primary 45",byte1:0,byte2:45},{id:46,label:"Primary 46",byte1:0,byte2:46},{id:47,label:"Primary 47",byte1:0,byte2:47},{id:48,label:"Primary 48",byte1:0,byte2:48},{id:49,label:"Primary 49",byte1:0,byte2:49},{id:50,label:"Primary 50",byte1:0,byte2:50},{id:51,label:"Primary 51",byte1:0,byte2:51},{id:52,label:"Primary 52",byte1:0,byte2:52},{id:53,label:"Primary 53",byte1:0,byte2:53},{id:54,label:"Primary 54",byte1:0,byte2:54},{id:55,label:"Primary 55",byte1:0,byte2:55},{id:56,label:"Primary 56",byte1:0,byte2:56},{id:57,label:"Primary 57",byte1:0,byte2:57},{id:58,label:"Primary 58",byte1:0,byte2:58},{id:59,label:"Primary 59",byte1:0,byte2:59},{id:60,label:"Primary 60",byte1:0,byte2:60},{id:61,label:"Primary 61",byte1:0,byte2:61},{id:62,label:"Primary 62",byte1:0,byte2:62},{id:63,label:"Primary 63",byte1:0,byte2:63},{id:64,label:"Primary 64",byte1:0,byte2:64},{id:65,label:"Primary 65",byte1:0,byte2:65},{id:66,label:"Primary 66",byte1:0,byte2:66},{id:67,label:"Primary 67",byte1:0,byte2:67},{id:68,label:"Primary 68",byte1:0,byte2:68},{id:69,label:"Primary 69",byte1:0,byte2:69},{id:70,label:"Primary 70",byte1:0,byte2:70},{id:71,label:"Primary 71",byte1:0,byte2:71},{id:72,label:"Primary 72",byte1:0,byte2:72},{id:73,label:"Primary 73",byte1:0,byte2:73},{id:74,label:"Primary 74",byte1:0,byte2:74},{id:75,label:"Primary 75",byte1:0,byte2:75},{id:76,label:"Primary 76",byte1:0,byte2:76},{id:77,label:"Primary 77",byte1:0,byte2:77},{id:78,label:"Primary 78",byte1:0,byte2:78},{id:79,label:"Primary 79",byte1:0,byte2:79},{id:80,label:"Primary 80",byte1:0,byte2:80},{id:81,label:"Primary 81",byte1:0,byte2:81},{id:82,label:"Primary 82",byte1:0,byte2:82},{id:83,label:"Primary 83",byte1:0,byte2:83},{id:84,label:"Primary 84",byte1:0,byte2:84},{id:85,label:"Primary 85",byte1:0,byte2:85},{id:86,label:"Primary 86",byte1:0,byte2:86},{id:87,label:"Primary 87",byte1:0,byte2:87},{id:88,label:"Primary 88",byte1:0,byte2:88},{id:89,label:"Primary 89",byte1:0,byte2:89},{id:90,label:"Primary 90",byte1:0,byte2:90},{id:91,label:"Primary 91",byte1:0,byte2:91},{id:92,label:"Primary 92",byte1:0,byte2:92},{id:93,label:"Primary 93",byte1:0,byte2:93},{id:94,label:"Primary 94",byte1:0,byte2:94},{id:95,label:"Primary 95",byte1:0,byte2:95},{id:96,label:"Primary 96",byte1:0,byte2:96},{id:97,label:"Primary 97",byte1:0,byte2:97},{id:98,label:"Primary 98",byte1:0,byte2:98},{id:99,label:"Primary 99",byte1:0,byte2:99},{id:100,label:"Primary 100",byte1:0,byte2:100},{id:101,label:"Primary 101",byte1:0,byte2:101},{id:102,label:"Primary 102",byte1:0,byte2:102},{id:103,label:"Primary 103",byte1:0,byte2:103},{id:104,label:"Primary 104",byte1:0,byte2:104},{id:105,label:"Primary 105",byte1:0,byte2:105},{id:106,label:"Primary 106",byte1:0,byte2:106},{id:107,label:"Primary 107",byte1:0,byte2:107},{id:108,label:"Primary 108",byte1:0,byte2:108},{id:109,label:"Primary 109",byte1:0,byte2:109},{id:110,label:"Primary 110",byte1:0,byte2:110},{id:111,label:"Primary 111",byte1:0,byte2:111},{id:112,label:"Primary 112",byte1:0,byte2:112},{id:113,label:"Primary 113",byte1:0,byte2:113},{id:114,label:"Primary 114",byte1:0,byte2:114},{id:115,label:"Primary 115",byte1:0,byte2:115},{id:116,label:"Primary 116",byte1:0,byte2:116},{id:117,label:"Primary 117",byte1:0,byte2:117},{id:118,label:"Primary 118",byte1:0,byte2:118},{id:119,label:"Primary 119",byte1:0,byte2:119},{id:120,label:"Primary 120",byte1:0,byte2:120},{id:121,label:"Primary 121",byte1:0,byte2:121},{id:122,label:"Primary 122",byte1:0,byte2:122},{id:123,label:"Primary 123",byte1:0,byte2:123},{id:124,label:"Primary 124",byte1:0,byte2:124},{id:125,label:"Primary 125",byte1:0,byte2:125},{id:126,label:"Primary 126",byte1:0,byte2:126},{id:127,label:"Primary 127",byte1:0,byte2:127},{id:128,label:"Primary 128",byte1:0,byte2:128},{id:129,label:"Primary 129",byte1:0,byte2:129},{id:130,label:"Primary 130",byte1:0,byte2:130},{id:131,label:"Primary 131",byte1:0,byte2:131},{id:132,label:"Primary 132",byte1:0,byte2:132},{id:133,label:"Primary 133",byte1:0,byte2:133},{id:134,label:"Primary 134",byte1:0,byte2:134},{id:135,label:"Primary 135",byte1:0,byte2:135},{id:136,label:"Primary 136",byte1:0,byte2:136},{id:137,label:"Primary 137",byte1:0,byte2:137},{id:138,label:"Primary 138",byte1:0,byte2:138},{id:139,label:"Primary 139",byte1:0,byte2:139},{id:140,label:"Primary 140",byte1:0,byte2:140},{id:141,label:"Primary 141",byte1:0,byte2:141},{id:142,label:"Primary 142",byte1:0,byte2:142},{id:143,label:"Primary 143",byte1:0,byte2:143},{id:144,label:"Primary 144",byte1:0,byte2:144},{id:145,label:"Primary 145",byte1:0,byte2:145},{id:146,label:"Primary 146",byte1:0,byte2:146},{id:147,label:"Primary 147",byte1:0,byte2:147},{id:148,label:"Primary 148",byte1:0,byte2:148},{id:149,label:"Primary 149",byte1:0,byte2:149},{id:150,label:"Primary 150",byte1:0,byte2:150},{id:151,label:"Primary 151",byte1:0,byte2:151},{id:152,label:"Primary 152",byte1:0,byte2:152},{id:153,label:"Primary 153",byte1:0,byte2:153},{id:154,label:"Primary 154",byte1:0,byte2:154},{id:155,label:"Primary 155",byte1:0,byte2:155},{id:156,label:"Primary 156",byte1:0,byte2:156},{id:157,label:"Primary 157",byte1:0,byte2:157},{id:158,label:"Primary 158",byte1:0,byte2:158},{id:159,label:"Primary 159",byte1:0,byte2:159},{id:160,label:"Primary 160",byte1:0,byte2:160},{id:217,label:"Black",byte1:0,byte2:217},{id:218,label:"White",byte1:0,byte2:218},{id:219,label:"Color Bkgd 1",byte1:0,byte2:219},{id:220,label:"Color Bkgd 2",byte1:0,byte2:220},{id:221,label:"FM 1",byte1:0,byte2:221},{id:222,label:"FM 2",byte1:0,byte2:222},{id:223,label:"FM 3",byte1:0,byte2:223},{id:224,label:"FM 4",byte1:0,byte2:224},{id:225,label:"FM 5",byte1:0,byte2:225},{id:226,label:"FM 6",byte1:0,byte2:226},{id:227,label:"FM 7",byte1:0,byte2:227},{id:228,label:"FM 8",byte1:0,byte2:228},{id:229,label:"FM 9",byte1:0,byte2:229},{id:230,label:"FM 10",byte1:0,byte2:230},{id:231,label:"FM 11",byte1:0,byte2:231},{id:232,label:"FM 12",byte1:0,byte2:232},{id:233,label:"FM 13",byte1:0,byte2:233},{id:234,label:"FM 14",byte1:0,byte2:234},{id:235,label:"FM 15",byte1:0,byte2:235},{id:236,label:"FM 16",byte1:0,byte2:236},{id:237,label:"FM 17",byte1:0,byte2:237},{id:238,label:"FM 18",byte1:0,byte2:238},{id:239,label:"FM 19",byte1:0,byte2:239},{id:240,label:"FM 20",byte1:0,byte2:240},{id:241,label:"FM 21",byte1:0,byte2:241},{id:242,label:"FM 22",byte1:0,byte2:242},{id:243,label:"FM 23",byte1:0,byte2:243},{id:244,label:"FM 24",byte1:0,byte2:244},{id:245,label:"FM 25",byte1:0,byte2:245},{id:246,label:"FM 26",byte1:0,byte2:246},{id:247,label:"FM 27",byte1:0,byte2:247},{id:248,label:"FM 28",byte1:0,byte2:248},{id:249,label:"FM 29",byte1:0,byte2:249},{id:250,label:"FM 30",byte1:0,byte2:250},{id:251,label:"FM 31",byte1:0,byte2:251},{id:252,label:"FM 32",byte1:0,byte2:252},{id:253,label:"CLIP1",byte1:0,byte2:253},{id:254,label:"CLIP2",byte1:0,byte2:254},{id:255,label:"CLIP3",byte1:0,byte2:255},{id:256,label:"CLIP4",byte1:1,byte2:0},{id:257,label:"CLIP5",byte1:1,byte2:1},{id:258,label:"CLIP6",byte1:1,byte2:2},{id:259,label:"CLIP7",byte1:1,byte2:3},{id:260,label:"CLIP8",byte1:1,byte2:4},{id:261,label:"DME MON V",byte1:1,byte2:5},{id:262,label:"DME MON K",byte1:1,byte2:6},{id:263,label:"ME 1 Out 1",byte1:1,byte2:7},{id:264,label:"ME 1 Out 2",byte1:1,byte2:8},{id:265,label:"ME 1 Out 3",byte1:1,byte2:9},{id:266,label:"ME 1 Out 4",byte1:1,byte2:10},{id:267,label:"ME 1 Out 5",byte1:1,byte2:11},{id:268,label:"ME 1 Out 6",byte1:1,byte2:12},{id:269,label:"ME 1 Out 7",byte1:1,byte2:13},{id:270,label:"ME 1 Out 8",byte1:1,byte2:14},{id:271,label:"ME 2 Out 1",byte1:1,byte2:15},{id:272,label:"ME 2 Out 2",byte1:1,byte2:16},{id:273,label:"ME 2 Out 3",byte1:1,byte2:17},{id:274,label:"ME 2 Out 4",byte1:1,byte2:18},{id:275,label:"ME 2 Out 5",byte1:1,byte2:19},{id:276,label:"ME 2 Out 6",byte1:1,byte2:20},{id:277,label:"ME 2 Out 7",byte1:1,byte2:21},{id:278,label:"ME 2 Out 8",byte1:1,byte2:22},{id:279,label:"ME 3 Out 1",byte1:1,byte2:23},{id:280,label:"ME 3 Out 2",byte1:1,byte2:24},{id:281,label:"ME 3 Out 3",byte1:1,byte2:25},{id:282,label:"ME 3 Out 4",byte1:1,byte2:26},{id:283,label:"ME 3 Out 5",byte1:1,byte2:27},{id:284,label:"ME 3 Out 6",byte1:1,byte2:28},{id:285,label:"ME 3 Out 7",byte1:1,byte2:29},{id:286,label:"ME 3 Out 8",byte1:1,byte2:30},{id:287,label:"ME 4 Out 1",byte1:1,byte2:31},{id:288,label:"ME 4 Out 2",byte1:1,byte2:32},{id:289,label:"ME 4 Out 3",byte1:1,byte2:33},{id:290,label:"ME 4 Out 4",byte1:1,byte2:34},{id:291,label:"ME 4 Out 5",byte1:1,byte2:35},{id:292,label:"ME 4 Out 6",byte1:1,byte2:36},{id:293,label:"ME 4 Out 7",byte1:1,byte2:37},{id:294,label:"ME 4 Out 8",byte1:1,byte2:38},{id:295,label:"ME 5 Out 1",byte1:1,byte2:39},{id:296,label:"ME 5 Out 2",byte1:1,byte2:40},{id:297,label:"ME 5 Out 3",byte1:1,byte2:41},{id:298,label:"ME 5 Out 4",byte1:1,byte2:42},{id:299,label:"ME 5 Out 5",byte1:1,byte2:43},{id:300,label:"ME 5 Out 6",byte1:1,byte2:44},{id:301,label:"ME 5 Out 7",byte1:1,byte2:45},{id:302,label:"ME 5 Out 8",byte1:1,byte2:46},{id:303,label:"P/P Out 1",byte1:1,byte2:47},{id:304,label:"P/P Out 2",byte1:1,byte2:48},{id:305,label:"P/P Out 3",byte1:1,byte2:49},{id:306,label:"P/P Out 4",byte1:1,byte2:50},{id:307,label:"P/P Out 5",byte1:1,byte2:51},{id:308,label:"P/P Out 6",byte1:1,byte2:52},{id:309,label:"P/P Out 7",byte1:1,byte2:53},{id:310,label:"P/P Out 8",byte1:1,byte2:54}]},u=[{id:"gpi1",label:"GPI 1",readByte:1},{id:"gpi2",label:"GPI 2",readByte:2},{id:"gpi3",label:"GPI 3",readByte:3},{id:"gpi4",label:"GPI 4",readByte:4},{id:"gpi5",label:"GPI 5",readByte:5},{id:"gpi6",label:"GPI 6",readByte:6},{id:"gpi7",label:"GPI 7",readByte:7},{id:"gpi8",label:"GPI 8",readByte:8}],b=[{id:"gpo1",label:"GPO 1",readByte:1},{id:"gpo2",label:"GPO 2",readByte:2},{id:"gpo3",label:"GPO 3",readByte:3},{id:"gpo4",label:"GPO 4",readByte:4},{id:"gpo5",label:"GPO 5",readByte:5},{id:"gpo6",label:"GPO 6",readByte:6},{id:"gpo7",label:"GPO 7",readByte:7},{id:"gpo8",label:"GPO 8",readByte:8}],I=[function(e,t){if(5!==t.readUint8(0))return!1;if(!r.map((e=>e.address)).includes(t.readUint8(1)))return!1;if(192!==t.readUint8(2))return!1;const n=t.readUInt8(3),i=t.readUInt8(4),s=r.find((e=>e.address===t.readUInt8(1)));if(!s)return!1;const o=d[e.config.model].find((e=>e.byte1===n&&e.byte2===i));return o?(console.log("INCOMING: FMXPT:",s,o),e.DATA.xpt[s.id]||(e.DATA.xpt[s.id]={}),e.DATA.xpt[s.id]=o.id,e.xptInterval&&clearInterval(e.xptInterval),e.xptInterval=setTimeout((()=>{e.updateVariableValues(),e.checkFeedbacks(),clearInterval(e.xptInterval)}),e.INTERVAL_RATE),!0):(console.log("FMXPT: (NO SOURCE MATCH)",{data1:n,data2:i,foundFM:s,foundSource:o}),!1)},function(e,t){if(4!==t.readUint8(0))return!1;if(!a.map((e=>e.address)).includes(t.readUint8(1)))return!1;if(192!==t.readUint8(2))return!1;const n=t.readUInt8(3),i=t.readUInt8(4),s=a.find((e=>e.address===t.readUInt8(1)));if(!s)return!1;const o=d[e.config.model].find((e=>e.byte1===n&&e.byte2===i));return o?(console.log("INCOMING: AUXXPT:",s,o),e.DATA.xpt[s.id]||(e.DATA.xpt[s.id]={}),e.DATA.xpt[s.id]=o.id,e.xptInterval&&clearInterval(e.xptInterval),e.xptInterval=setTimeout((()=>{e.updateVariableValues(),e.checkFeedbacks(),clearInterval(e.xptInterval)}),e.INTERVAL_RATE),!0):(console.log("AUXXPT: (NO SOURCE MATCH)",{data1:n,data2:i,foundAux:s,foundSource:o}),!1)},function(e,t){if(4!==t.readUint8(0))return!1;if(!o.map((e=>e.address)).includes(t.readUint8(1)))return!1;const n=t.readUint8(2),i=l[e.config.model]?.find((e=>n===e.writeByte));if(!i)return e.log("error","INCOMING ME XPT - NO BUS MATCH"),!1;const s=1&t.readUInt8(3),r=t.readUInt8(4),a=o.find((e=>e.address===t.readUInt8(1)));if(!a)return!1;const c=d[e.config.model].find((e=>e.byte1===s&&e.byte2===r));return c?(console.log("INCOMING: MEXPT:",a,i,c),e.DATA.xpt[a.id]||(e.DATA.xpt[a.id]={}),e.DATA.xpt[a.id][i.id]||(e.DATA.xpt[a.id][i.id]={}),e.DATA.xpt[a.id][i.id]=c.id,e.xptInterval&&clearInterval(e.xptInterval),e.xptInterval=setTimeout((()=>{e.updateVariableValues(),e.checkFeedbacks(),clearInterval(e.xptInterval)}),500),!0):(console.log("INCOMING: MEXPT: (NO SOURCE MATCH)",{foundME:a,foundBus:i,foundSource:c}),e.log("error","INCOMING ME XPT - NO SOURCE MATCH"),!1)},function(e,t){const n=t.readUint8(0);if(n<5)return!1;if(32!==t.readUint8(1))return!1;if(240!==t.readUint8(2))return!1;if(80!==t.readUint8(3))return!1;if(n>21)return console.log("ughhhg","text too long or something."),!1;const i=t.readUInt8(4),s=t.readUInt8(5),o=d[e.config.model].find((e=>e.byte1===i&&e.byte2===s));if(!o)return e.log("error","INCOMING SOURCE NAME - NO SOURCE MATCH"),console.log("INCOMING SOURCE NAME - NO SOURCE MATCH"),!1;let r="";n>=6&&255!=t.readUInt8(6)&&(r=t.subarray(6,n+1).toString());const a=e.DATA.sourceNames.find((e=>e.id===o?.id));return a?a.name=r:e.DATA.sourceNames.push({id:o?.id,name:r}),e.sourceNameUpdateTimer&&clearTimeout(e.sourceNameUpdateTimer),e.sourceNameUpdateTimer=setTimeout((()=>{e.updateActions(),e.updateFeedbacks(),e.updateVariableValues(),delete e.sourceNameUpdateTimer}),e.INTERVAL_RATE),!0},function(e,t){const n=1&t.readUInt8(3),i=t.readUInt8(4);return console.log("INCOMING: GPI IN:",n,i),e.gpioUpdateTimer&&clearInterval(e.gpioUpdateTimer),e.gpioUpdateTimer=setTimeout((()=>{e.updateVariableValues(),e.checkFeedbacks(),clearInterval(e.gpioUpdateTimer)}),e.INTERVAL_RATE),!0},function(e,t){const n=1&t.readUInt8(3),i=t.readUInt8(4);return console.log("INCOMING: GPI OUT:",n,i),e.gpioUpdateTimer&&clearInterval(e.gpioUpdateTimer),e.gpioUpdateTimer=setTimeout((()=>{e.updateVariableValues(),e.checkFeedbacks(),clearInterval(e.gpioUpdateTimer)}),e.INTERVAL_RATE),!0}];function p(e){e.log("debug","initConnection"),e.config.intervalRate&&(e.INTERVAL_RATE=e.config.intervalRate),e.config.host&&""!==e.config.host&&(e.log("info",`Connecting to ${e.config.host}`),e.updateStatus(i.InstanceStatus.Connecting,"Connecting"),e.tcp=new i.TCPHelper(e.config.host,e.config.port),e.PROTOCOL_STATE="IDLE",e.tcp.on("connect",(()=>{e.incomingData=Buffer.alloc(0),e.incomingCommandQueue=[],e.outgoingCommandQueue=[],e.DATA={sourceNames:[],xpt:[]},e.PROTOCOL_STATE="WAITING",e.log("debug","Connected, waiting for ACK"),e.updateStatus(i.InstanceStatus.Connecting,"Waiting for ack")})),e.tcp.on("data",(t=>{if(e.incomingData=Buffer.concat([e.incomingData,t]),132===e.incomingData.readUInt8(0)&&(console.log("got ACK"),e.incomingData=e.incomingData.subarray(1),e.updateStatus(i.InstanceStatus.Ok),e.log("debug","ACK received, connected."),"WAITING"===e.PROTOCOL_STATE&&function(e){const t=Buffer.alloc(3);for(const n of o)for(const i of l[e.config.model])t.writeUInt8(2,0),t.writeUInt8(n.address,1),t.writeUInt8(i.readByte,2),m(e,t,!1);const n=Buffer.alloc(3);for(const t of a)n.writeUInt8(2,0),n.writeUInt8(t.address,1),n.writeUInt8(64,2),m(e,n,!1);const i=Buffer.alloc(3);for(const t of r)i.writeUInt8(2,0),i.writeUInt8(t.address,1),i.writeUInt8(64,2),m(e,i,!1);const s=Buffer.alloc(6);for(const t of d[e.config.model])s.writeUInt8(5,0),s.writeUInt8(32,1),s.writeUInt8(112,2),s.writeUInt8(80,3),s.writeUInt8(t.byte1,4),s.writeUInt8(t.byte2,5),m(e,s,!1);const c=Buffer.alloc(4);c.writeUInt8(3,0),c.writeUInt8(2,1),c.writeUInt8(38,2),c.writeUInt8(1,3),m(e,c,!1)}(e),e.PROTOCOL_STATE="OK"),"OK"===e.PROTOCOL_STATE)for(;e.incomingData.length>0;){const t=e.incomingData.readUInt8(0);if(!(e.incomingData.length>=t))break;{const n=e.incomingData.subarray(0,t+1);e.incomingData=e.incomingData.subarray(t+1),e.incomingCommandQueue.push(n)}}for(;e.incomingCommandQueue.length>0;){const t=e.incomingCommandQueue.shift();t&&C(e,t)}})),e.tcp.on("error",(t=>{e.log("error",`Error: ${t}`),e.PROTOCOL_STATE="IDLE",e.updateStatus(i.InstanceStatus.UnknownError,"Connection error"),String(t).indexOf("ECONNREFUSED")>-1&&(e.tcp.destroy(),e.tcp=void 0,e.log("info","Connection refused. Will attempt to reconnect in 30 seconds."),e.reconnectInterval=setInterval((()=>{e.log("info","Attempting to reconnect..."),p(e),e.reconnectInterval=void 0}),3e4))})))}function C(e,t){!function(e,t){for(const n of I)if(n(e,t))return;console.log("UNKNOWN COMMAND>",t)}(e,t)}function h(e,t,n){e.log("debug",`xptAUX: ${t}, ${n}`);const i=Buffer.alloc(5),s=a.find((e=>e.id===t)),o=d[e.config.model].find((e=>e.id===parseInt(n)));if(s&&o){const t=s.address,n=o.byte1,r=o.byte2;i.writeUInt8(4,0),i.writeUInt8(t,1),i.writeUInt8(192,2),i.writeUInt8(n,3),i.writeUInt8(r,4),m(e,i)}}function m(e,t,n=!0){if(void 0!==e.tcp&&1==e.tcp.isConnected){if(1==e.config.verbose&&n){const n=t.toString("hex").match(/.{1,2}/g),i=n?n.join(" "):"";e.log("debug",`Sending: ${i}`)}e.outgoingCommandQueue.push(Buffer.from(t)),e.outputTimer||(e.outputTimer=setInterval((()=>{if(e.outgoingCommandQueue.length>0){const t=e.outgoingCommandQueue.shift();t&&e.tcp.send(t)}else clearInterval(e.outputTimer),e.outputTimer=void 0}),10))}}function y(e){const t={},n=Object.values(d[e.config.model]).map((t=>{const n=e.DATA.sourceNames.find((e=>e.id===t.id));return n&&n.name&&(t.label=`${t.label} (${n.name})`),t}));t.xptME={name:"XPT: M/E",options:[{type:"dropdown",id:"eff",label:"M/E Selection",default:o[0].id,choices:o},{type:"dropdown",id:"bus",label:"Bus Selection",default:l[e.config.model][0].id,choices:l[e.config.model]},{type:"dropdown",id:"source",label:"Source Selection",default:n[0].id,choices:n}],callback:async t=>{const n=t.options.eff,i=t.options.bus,s=t.options.source;!function(e,t,n,i){console.log(`xptME: ${t}, ${n}, ${i}`);const s=Buffer.alloc(5),r=o.find((e=>e.id===t)),a=l[e.config.model].find((e=>e.id===n)),c=d[e.config.model].find((e=>e.id===parseInt(i)));if(r&&a&&c){const t=r.address,n=a.writeByte,i=c.byte1,o=c.byte2;s.writeUInt8(4,0),s.writeUInt8(t,1),s.writeUInt8(n,2),s.writeUInt8(i,3),s.writeUInt8(o,4),m(e,s)}}(e,n,i,s)}},t.xptAUX={name:"XPT: AUX",options:[{type:"dropdown",id:"aux",label:"Aux Selection",default:a[0].id,choices:a},{type:"dropdown",id:"source",label:"Source Selection",default:n[0].id,choices:n}],callback:async t=>{const n=t.options.aux,i=t.options.source;h(e,n,i)}},t.copyAUX={name:"Copy AUX",options:[{type:"dropdown",id:"aux",label:"COPY FROM: Aux Selection",default:a[0].id,choices:a},{type:"dropdown",id:"copyAux",label:"COPY TO: Aux Selection",default:a[0].id,choices:a}],callback:async t=>{const n=t.options.aux,i=t.options.copyAux;!function(e,t,n){e.log("debug",`copyAUX: FROM ${t}, TO ${n}`);const i=e.DATA.xpt[t];i&&h(e,n,i.toString())}(e,n,i)}},t.transitionME={name:"Transition M/E",options:[{type:"dropdown",id:"eff",label:"M/E Selection",default:o[0].id,choices:o},{type:"dropdown",id:"cmd",label:"Command",default:c[0].id,choices:c},{type:"number",id:"transRate",label:"Transition Rate (frames)",default:30,min:0,max:999}],callback:async t=>{const n=t.options.eff,i=t.options.cmd,s=t.options.transRate;!function(e,t,n,i){e.log("debug",`transitionME: ${t}, ${n}`);const s=Buffer.alloc(7),r=o.find((e=>e.id===t)),a=c.find((e=>e.id===n));if(r&&a){const t=r.address,n=a.writeByte,o=i>>8&255,c=255&i;s.writeUInt8(6,0),s.writeUInt8(t,1),s.writeUInt8(n,2),s.writeUInt8(22,3),s.writeUInt8(0,4),s.writeUInt8(o,5),s.writeUInt8(c,6),m(e,s)}}(e,n,i,s)}},t.transitionMECancel={name:"Transition M/E Cancel",options:[{type:"dropdown",id:"eff",label:"M/E Selection",default:o[0].id,choices:o},{type:"dropdown",id:"cmd",label:"Command",default:c[0].id,choices:c}],callback:async t=>{const n=t.options.eff,i=t.options.cmd;!function(e,t,n){e.log("debug",`transitionMECancel: ${t}, ${n}`);const i=Buffer.alloc(5),s=o.find((e=>e.id===t)),r=c.find((e=>e.id===n));if(s&&r){const t=s.address,n=r.writeByte;i.writeUInt8(4,0),i.writeUInt8(t,1),i.writeUInt8(n,2),i.writeUInt8(25,3),i.writeUInt8(0,4),m(e,i)}}(e,n,i)}},t.keyOnOff={name:"Key On/Off",options:[{type:"dropdown",id:"eff",label:"M/E Selection",default:o[0].id,choices:o},{type:"dropdown",id:"key",label:"Key Number",default:g[0].id,choices:g},{type:"dropdown",id:"onoff",label:"On/Off",default:"on",choices:[{id:"on",label:"On"},{id:"off",label:"Off"}]}],callback:async t=>{const n=t.options.eff,i=t.options.key,s=t.options.onoff;!function(e,t,n,i){e.log("debug",`keyOnOff: ${t}, ${n} ${i}`);const s=Buffer.alloc(4),r=o.find((e=>e.id===t)),a=g.find((e=>e.id===n));if(r&&a){const t=r.address,n=a.address;s.writeUInt8(3,0),s.writeUInt8(t,1),"on"==i?s.writeUInt8(218,2):s.writeUInt8(154,2),s.writeUInt8(n,3),m(e,s)}}(e,n,i,s)}};const i=o.slice().reverse();t.recallSnapshot={name:"Recall Snapshot",options:[],callback:async t=>{const n=[],s=t.options.registerNumber,o=[],r=[];for(const e of i)t.options[`regionSelect_part1_${e.id}`]&&n.push(e.id);for(let e=8;e>0;e--)t.options[`regionSelect_part2_${e}`]&&o.push(e);for(const e of i)t.options[`regionSelect_part3_${e.id}`]&&r.push(e.id);!function(e,t,n,i,s){e.log("debug",`recallSnapshot: ${t}, ${n}, ${i}, ${s}`);const o=Buffer.alloc(7);let r=0,a=0,c=0;const l=t.includes("me5")?1:0,g=t.includes("me4")?1:0,d=t.includes("me3")?1:0,u=t.includes("me2")?1:0,b=t.includes("me1")?1:0,I=t.includes("pp")?1:0;r=parseInt(`00${l}${g}${d}${u}${b}${I}`,2);const p=i.includes(8)?1:0,C=i.includes(7)?1:0,h=i.includes(6)?1:0,y=i.includes(5)?1:0,Z=i.includes(4)?1:0,G=i.includes(3)?1:0,B=i.includes(2)?1:0,A=i.includes(1)?1:0;a=parseInt(`${p}${C}${h}${y}${Z}${G}${B}${A}`,2);const W=s.includes("me5")?1:0,f=s.includes("me4")?1:0,V=s.includes("me3")?1:0,v=s.includes("me2")?1:0,R=s.includes("me1")?1:0,Y=s.includes("pp")?1:0;c=parseInt(`00${W}${f}${V}${v}${R}${Y}`,2),o.writeUInt8(6,0),o.writeUInt8(33,1),o.writeUInt8(144,2),o.writeUInt8(r,3),o.writeUInt8(n,4),o.writeUInt8(a,5),o.writeUInt8(c,6),m(e,o)}(e,n,s,o,r)}};for(const e of i){const n={type:"checkbox",id:`regionSelect_part1_${e.id}`,label:`Region Select Part 1 - ${e.label}`,default:!1};t.recallSnapshot.options.push(n)}t.recallSnapshot.options.push({type:"number",id:"registerNumber",label:"Register Number",default:1,min:1,max:99});for(let e=8;e>0;e--){const n={type:"checkbox",id:`regionSelect_part2_${e}`,label:`Region Select Part 2 - User ${e}`,default:!1};t.recallSnapshot.options.push(n)}for(const e of i){const n={type:"checkbox",id:`regionSelect_part3_${e.id}`,label:`Region Select Part 3 - ${e.label} SUB`,default:!1};t.recallSnapshot.options.push(n)}t.macroRecall={name:"Macro Recall",options:[{type:"number",id:"macroNumber",label:"Macro Register Number",default:1,min:1,max:999}],callback:async t=>{const n=t.options.macroNumber;!function(e,t){e.log("debug",`macroRecall: ${t}`);const n=Buffer.alloc(7);let i=0,s=0;const o=parseInt(t);i=o>>8&255,s=255&o,n.writeUInt8(6,0),n.writeUInt8(34,1),n.writeUInt8(145,2),n.writeUInt8(0,3),n.writeUInt8(23,4),n.writeUInt8(i,5),n.writeUInt8(s,6),m(e,n)}(e,n)}},t.macroTake={name:"Macro Take",options:[],callback:async()=>{!function(e){e.log("debug","macroTake");const t=Buffer.alloc(5);t.writeUInt8(4,0),t.writeUInt8(34,1),t.writeUInt8(144,2),t.writeUInt8(0,3),t.writeUInt8(28,4),m(e,t)}(e)}},t.gpiIn={name:"Activate GPI In",options:[{type:"number",id:"gpiNumber",label:"GPI Number",default:1,min:1,max:999},{type:"dropdown",id:"gpiState",label:"GPI State",default:0,choices:[{id:0,label:"High"},{id:1,label:"Low"}]}],callback:async t=>{const n=t.options.gpiNumber,i=t.options.gpiState;!function(e,t,n){e.log("debug",`activate gpiIn: ${t}, ${n}`);const i=Buffer.alloc(5);i.writeUInt8(4,0),i.writeUInt8(38,1),i.writeUInt8(128,2),i.writeUInt8(t,3),i.writeUInt8(n,4),m(e,i)}(e,n,i)}},t.gpiOut={name:"Activate GPI Out",options:[{type:"number",id:"gpiNumber",label:"GPI Number",default:1,min:1,max:999},{type:"dropdown",id:"gpiState",label:"GPI State",default:1,choices:[{id:1,label:"High"},{id:0,label:"Low"}]}],callback:async t=>{const n=t.options.gpiNumber,i=t.options.gpiState;!function(e,t,n){e.log("debug",`activate gpiOut: ${t}, ${n}`);const i=Buffer.alloc(5);i.writeUInt8(4,0),i.writeUInt8(38,1),i.writeUInt8(129,2),i.writeUInt8(t,3),i.writeUInt8(n,4),m(e,i)}(e,n,i)}},1==e.config.allowCustomCommands&&(t.customCommand={name:"Send Custom Command",options:[{type:"static-text",id:"info",label:"Send a custom command string to the device",value:"The command must conform to the Sony XVS protocol or it will be rejected. Use with caution."},{type:"static-text",id:"example",label:"Example",value:"0431C00001 would send Source 1 to Aux 2."},{type:"textinput",label:"Command String",id:"commandString",default:""}],callback:async t=>{const n=await e.parseVariablesInString(t.options.commandString?.toString()??"");!function(e,t){e.log("debug",`customCommand: ${t}`),m(e,Buffer.from(t,"hex"))}(e,n)}}),e.setActionDefinitions(t)}class Z extends i.InstanceBase{config;constructor(e){super(e)}tcp;DATA={sourceNames:[],xpt:[]};xptInterval=void 0;sourceNameUpdateTimer=void 0;gpioUpdateTimer=void 0;INTERVAL_RATE=500;INTERVAL=void 0;PROTOCOL_STATE="IDLE";incomingData=Buffer.alloc(0);incomingCommandQueue=[];outgoingCommandQueue=[];outputTimer=void 0;reconnectInterval=void 0;async init(e){await this.configUpdated(e)}async destroy(){this.log("debug","destroy")}async configUpdated(e){this.config=e,this.updateStatus(i.InstanceStatus.Connecting),this.updateActions(),this.updateFeedbacks(),this.updateVariableDefinitions(),p(this)}getConfigFields(){return[{type:"static-text",id:"info",label:"Information",width:12,value:"This module is for controlling Sony switchers that support the XVS serial tally protocol."},{type:"textinput",id:"host",label:"Target IP",width:8,regex:i.Regex.IP},{type:"number",id:"port",label:"Target Port",width:4,min:1,max:65535,default:10010},{type:"dropdown",id:"model",label:"Model",width:8,default:s[0].id,choices:s},{type:"static-text",id:"advancedSeperator",label:"",width:12,value:"
"},{type:"checkbox",id:"advanced",label:"Advanced settings",width:12,default:!1},{type:"checkbox",id:"allowCustomCommands",label:"Allow Custom Commands",width:12,default:!1,isVisible:e=>!!e.advanced},{type:"number",id:"intervalRate",label:"Update Interval Rate (ms)",width:4,min:100,max:6e4,default:500,isVisible:e=>!!e.advanced},{type:"static-text",id:"intervalRateInfo",label:"",width:8,value:"This is the interval at which the module will update variables, feedbacks, and other data as it arrives from the switcher.",isVisible:e=>!!e.advanced},{type:"checkbox",id:"verbose",label:"Verbose logging",width:4,default:!1,isVisible:e=>!!e.advanced},{type:"static-text",id:"verboseInfo",label:"",width:8,value:"Enable this to log all commands and responses to the debug log.",isVisible:e=>!!e.advanced}]}updateActions(){y(this)}updateFeedbacks(){!function(e){const t={};t.xptMEState={name:"Selected Source is on Selected Bus of M/E",type:"boolean",defaultStyle:{bgcolor:(0,i.combineRgb)(255,0,0),color:(0,i.combineRgb)(0,0,0)},options:[{type:"dropdown",id:"eff",label:"M/E Selection",default:o[0].id,choices:o},{type:"dropdown",id:"bus",label:"Bus Selection",default:l[e.config.model][0].id,choices:l[e.config.model]},{type:"dropdown",id:"source",label:"Source Selection",default:d[e.config.model][0].id,choices:d[e.config.model]}],callback:t=>{const n=t.options.eff,i=t.options.bus,s=t.options.source;return!(!e.DATA.xpt[n]||!e.DATA.xpt[n][i]||e.DATA.xpt[n][i]!=s)}},t.xptAUXState={name:"Selected Source is on Selected Aux",type:"boolean",defaultStyle:{bgcolor:(0,i.combineRgb)(255,0,0),color:(0,i.combineRgb)(0,0,0)},options:[{type:"dropdown",id:"aux",label:"Aux Selection",default:a[0].id,choices:a},{type:"dropdown",id:"source",label:"Source Selection",default:d[e.config.model][0].id,choices:d[e.config.model]}],callback:t=>{const n=t.options.aux,i=t.options.source;return e.DATA.xpt[n]==i}},e.setFeedbackDefinitions(t)}(this)}updateVariableDefinitions(){!function(e){const t=[];for(const n of o)for(const i of l[e.config.model])t.push({name:`${n.label} ${i.label}`,variableId:`${n.id}_${i.id}`});for(const n of d[e.config.model])t.push({name:`${n.label} Name`,variableId:`source_${n.id}`});for(const e of a)t.push({name:`${e.label}`,variableId:`${e.id}`});for(const e of r)t.push({name:`${e.label}`,variableId:`${e.id}`});for(const e of u)t.push({name:`${e.label} State`,variableId:`${e.id}`});for(const e of b)t.push({name:`${e.label} State`,variableId:`${e.id}`});e.setVariableDefinitions(t)}(this)}updateVariableValues(){!function(e){const t={};for(const n of o)for(const i of l[e.config.model]){const s=e.DATA.xpt[n.id]?.[i.id],o=d[e.config.model].find((e=>e.id===s))?.label;if(s&&o){t[`${n.id}_${i.id}`]=o;const r=e.DATA.sourceNames.find((e=>e.id===s));r&&(t[`${n.id}_${i.id}`]=r.name)}else e.log("debug",`UpdateVariableValues: No source found for ${n.id}_${i.id}`)}for(const n of d[e.config.model]){const i=e.DATA.sourceNames.find((e=>e.id===n.id));i?t[`source_${n.id}`]=i.name:e.log("debug",`UpdateVariableValues: No source name found for ${n.id}`)}for(const n of a){const i=e.DATA.xpt[n.id],s=d[e.config.model].find((e=>e.id===i))?.label;if(i&&s){t[`${n.id}`]=s;const o=e.DATA.sourceNames.find((e=>e.id===i));o&&(t[`${n.id}`]=o.name)}else e.log("debug",`UpdateVariableValues: No source found for ${n.id}`)}for(const n of r){const i=e.DATA.xpt[n.id],s=d[e.config.model].find((e=>e.id===i))?.label;if(i&&s){t[`${n.id}`]=s;const o=e.DATA.sourceNames.find((e=>e.id===i));o&&(t[`${n.id}`]=o.name)}else e.log("debug",`UpdateVariableValues: No source found for ${n.id}`)}for(const n of u){const i=e.DATA.gpi?.[n.id]??null;t[`${n.id}`]=i?"On":"Off"}for(const n of b){const i=e.DATA.gpo?.[n.id]??null;t[`${n.id}`]=i?"On":"Off"}e.setVariableValues(t)}(this)}}(0,i.runEntrypoint)(Z,[])},1635:(e,t,n)=>{"use strict";n.r(t),n.d(t,{__addDisposableResource:()=>K,__assign:()=>o,__asyncDelegator:()=>f,__asyncGenerator:()=>W,__asyncValues:()=>V,__await:()=>A,__awaiter:()=>I,__classPrivateFieldGet:()=>S,__classPrivateFieldIn:()=>w,__classPrivateFieldSet:()=>N,__createBinding:()=>C,__decorate:()=>a,__disposeResources:()=>k,__esDecorate:()=>l,__exportStar:()=>h,__extends:()=>s,__generator:()=>p,__importDefault:()=>H,__importStar:()=>X,__makeTemplateObject:()=>v,__metadata:()=>b,__param:()=>c,__propKey:()=>d,__read:()=>y,__rest:()=>r,__rewriteRelativeImportExtension:()=>_,__runInitializers:()=>g,__setFunctionName:()=>u,__spread:()=>Z,__spreadArray:()=>B,__spreadArrays:()=>G,__values:()=>m,default:()=>J});var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},i(e,t)};function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var o=function(){return o=Object.assign||function(e){for(var t,n=1,i=arguments.length;n=0;a--)(s=e[a])&&(r=(o<3?s(r):o>3?s(t,n,r):s(t,n))||r);return o>3&&r&&Object.defineProperty(t,n,r),r}function c(e,t){return function(n,i){t(n,i,e)}}function l(e,t,n,i,s,o){function r(e){if(void 0!==e&&"function"!=typeof e)throw new TypeError("Function expected");return e}for(var a,c=i.kind,l="getter"===c?"get":"setter"===c?"set":"value",g=!t&&e?i.static?e:e.prototype:null,d=t||(g?Object.getOwnPropertyDescriptor(g,i.name):{}),u=!1,b=n.length-1;b>=0;b--){var I={};for(var p in i)I[p]="access"===p?{}:i[p];for(var p in i.access)I.access[p]=i.access[p];I.addInitializer=function(e){if(u)throw new TypeError("Cannot add initializers after decoration has completed");o.push(r(e||null))};var C=(0,n[b])("accessor"===c?{get:d.get,set:d.set}:d[l],I);if("accessor"===c){if(void 0===C)continue;if(null===C||"object"!=typeof C)throw new TypeError("Object expected");(a=r(C.get))&&(d.get=a),(a=r(C.set))&&(d.set=a),(a=r(C.init))&&s.unshift(a)}else(a=r(C))&&("field"===c?s.unshift(a):d[l]=a)}g&&Object.defineProperty(g,i.name,d),u=!0}function g(e,t,n){for(var i=arguments.length>2,s=0;s0&&s[s.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!s||a[1]>s[0]&&a[1]=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function y(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var i,s,o=n.call(e),r=[];try{for(;(void 0===t||t-- >0)&&!(i=o.next()).done;)r.push(i.value)}catch(e){s={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(s)throw s.error}}return r}function Z(){for(var e=[],t=0;t1||a(e,t)}))},t&&(i[e]=t(i[e])))}function a(e,t){try{(n=s[e](t)).value instanceof A?Promise.resolve(n.value.v).then(c,l):g(o[0][2],n)}catch(e){g(o[0][3],e)}var n}function c(e){a("next",e)}function l(e){a("throw",e)}function g(e,t){e(t),o.shift(),o.length&&a(o[0][0],o[0][1])}}function f(e){var t,n;return t={},i("next"),i("throw",(function(e){throw e})),i("return"),t[Symbol.iterator]=function(){return this},t;function i(i,s){t[i]=e[i]?function(t){return(n=!n)?{value:A(e[i](t)),done:!1}:s?s(t):t}:s}}function V(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=m(e),t={},i("next"),i("throw"),i("return"),t[Symbol.asyncIterator]=function(){return this},t);function i(n){t[n]=e[n]&&function(t){return new Promise((function(i,s){!function(e,t,n,i){Promise.resolve(i).then((function(t){e({value:t,done:n})}),t)}(i,s,(t=e[n](t)).done,t.value)}))}}}function v(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}var R=Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t},Y=function(e){return Y=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},Y(e)};function X(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=Y(e),i=0;i{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.hmd=e=>((e=Object.create(e)).children||(e.children=[]),Object.defineProperty(e,"exports",{enumerable:!0,set:()=>{throw new Error("ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: "+e.id)}}),e),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n(n.s=8515)})(); \ No newline at end of file diff --git a/sony-serialtally/package.json b/sony-serialtally/package.json index d0d5e998..11cbd14e 100644 --- a/sony-serialtally/package.json +++ b/sony-serialtally/package.json @@ -1 +1 @@ -{"name":"Sony Serial Tally","version":"1.2.0","license":"MIT","type":"commonjs","dependencies":{}} \ No newline at end of file +{"name":"Sony Serial Tally","version":"1.3.0","license":"MIT","type":"commonjs","dependencies":{}} \ No newline at end of file