@datadog/apps-frontend 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/_chunks/chunk-64RLSXHA.js +184 -0
- package/dist/src/_chunks/chunk-64RLSXHA.js.map +7 -0
- package/dist/src/_chunks/chunk-BWBMAWDD.js +235 -0
- package/dist/src/_chunks/{chunk-OEPH347K.js.map → chunk-BWBMAWDD.js.map} +3 -3
- package/dist/src/_chunks/chunk-E6L6DSL7.js +230 -0
- package/dist/src/_chunks/{chunk-LEEYMNMO.js.map → chunk-E6L6DSL7.js.map} +1 -1
- package/dist/src/_chunks/chunk-OF23NNWB.js +34 -0
- package/dist/src/_chunks/{chunk-XSHCFEOH.js.map → chunk-OF23NNWB.js.map} +1 -1
- package/dist/src/_chunks/chunk-ONCDAC2F.js +802 -0
- package/dist/src/_chunks/{chunk-EYBITW7J.js.map → chunk-ONCDAC2F.js.map} +2 -2
- package/dist/src/_chunks/chunk-SSORLL57.js +219 -0
- package/dist/src/_chunks/{chunk-D43RPVCF.js.map → chunk-SSORLL57.js.map} +1 -1
- package/dist/src/_chunks/chunk-VSZMABRM.js +54 -0
- package/dist/src/_chunks/{chunk-2V2HASKF.js.map → chunk-VSZMABRM.js.map} +1 -1
- package/dist/src/deep-links/react/index.js +8 -1
- package/dist/src/druids/react/index.js +25 -1
- package/dist/src/druids/react/index.js.map +1 -1
- package/dist/src/embedding/react/index.js +2908 -1
- package/dist/src/embedding/react/index.js.map +1 -1
- package/dist/src/inputs/published-definition.d.ts +13 -0
- package/dist/src/inputs/react/index.js +9 -1
- package/dist/src/inputs/schemas/index.js +15 -1
- package/package.json +2 -1
- package/dist/src/_chunks/chunk-2V2HASKF.js +0 -7
- package/dist/src/_chunks/chunk-D43RPVCF.js +0 -7
- package/dist/src/_chunks/chunk-DETZPDFA.js +0 -7
- package/dist/src/_chunks/chunk-DETZPDFA.js.map +0 -7
- package/dist/src/_chunks/chunk-EYBITW7J.js +0 -7
- package/dist/src/_chunks/chunk-LEEYMNMO.js +0 -7
- package/dist/src/_chunks/chunk-OEPH347K.js +0 -7
- package/dist/src/_chunks/chunk-XSHCFEOH.js +0 -7
|
@@ -3,5 +3,2912 @@
|
|
|
3
3
|
* Copyright 2019-Present Datadog, Inc.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import{a as gn,b as Rn}from"../../_chunks/chunk-D43RPVCF.js";import{a as vn,b as An,c as In,d as _n}from"../../_chunks/chunk-2V2HASKF.js";import"../../_chunks/chunk-EYBITW7J.js";import{A as b,B as k,C as w,D as ge,a as Fe,b as r,c as p,d as l,e as a,f as qe,g as En,h as Tn,i as xe,j as Cn,k as On,l as et,m as It,n as B,o as tt,p as bn,q as yn,r as _t,s as Dt,t as S,u as J,v as x,w as y,x as me,y as P,z as u}from"../../_chunks/chunk-LEEYMNMO.js";import{createElement as or,useEffect as rr,useState as ir}from"react";var go=/^https:\/\/(?:[a-zA-Z0-9-]+\.)*(?:datadoghq\.(?:com|eu)|ddog-gov\.com)$/,Eo=/^https:\/\/(?:[a-zA-Z0-9-]+\.)*(?:datad0g\.com|datad0g\.eu|staging\.dog|prod\.dog)$/,To=/^https?:\/\/(?:localhost|127\.0\.0\.1)(?::\d+)?$/;function Dn(t){return go.test(t)||Eo.test(t)||To.test(t)}var Mn="dd-apps-frontend-bootstrap",Pn=1;function Oo(t,e,n){let{data:o}=n;return n.source!==t||n.ports.length!==0||!b(o)||o.namespace!==Mn||o.version!==Pn||o.type!=="accepted"&&o.type!=="rejected-origin"||o.attemptId!==e?{status:"ignored"}:Dn(n.origin)?o.type==="rejected-origin"?typeof o.origin=="string"?{status:"rejected-origin",origin:o.origin}:{status:"ignored"}:{status:"accepted"}:{status:"rejected-origin",origin:n.origin}}function wn(t,e,n,o=1e4){if(n.aborted)return Promise.resolve(u({code:"ABORTED"}));let i=t.parent;if(i===t)return Promise.resolve(u({code:"TRANSPORT_FAILED",cause:new Error("The app is not running in an iframe.")}));let s=me("bootstrap"),d=new MessageChannel;return new Promise(c=>{let h=!1,f=!1,m=!1,C,_=M=>{h||(h=!0,t.removeEventListener("message",O),n.removeEventListener("abort",D),C!==void 0&&globalThis.clearTimeout(C),M.ok||(w("failed app bootstrap port",()=>d.port1.close()),f||w("untransferred app bootstrap port",()=>d.port2.close())),c(M))},O=M=>{let T=Oo(i,s,M);T.status==="accepted"?_(P(d.port1)):T.status==="rejected-origin"&&_(u({code:"ORIGIN_REJECTED",origin:T.origin}))},D=()=>_(u({code:"ABORTED"})),H=()=>{if(!(m||h)){m=!0,C=globalThis.setTimeout(()=>_(u({code:"TIMED_OUT",timeoutMs:o})),Math.max(0,o));try{i.postMessage({namespace:Mn,version:Pn,type:"request",attemptId:s,documentId:e},"*",[d.port2]),f=!0}catch(M){_(u({code:"TRANSPORT_FAILED",cause:M}))}}};if(t.addEventListener("message",O),n.addEventListener("abort",D,{once:!0}),n.aborted){D();return}H()})}var Ln=me("document");var Nn="dd-apps-frontend-compatibility",Sn=1,bo=64;function yo(t,e,n,o){return n.aborted?Promise.resolve({ok:!1,error:{code:"ABORTED"}}):new Promise(i=>{let s=!1,d,c=m=>{s||(s=!0,t.removeEventListener("message",h),n.removeEventListener("abort",f),d!==void 0&&globalThis.clearTimeout(d),i(m))},h=m=>c({ok:!0,value:m}),f=()=>c({ok:!1,error:{code:"ABORTED"}});t.addEventListener("message",h),n.addEventListener("abort",f,{once:!0}),d=globalThis.setTimeout(()=>c({ok:!1,error:{code:"TIMED_OUT",timeoutMs:e}}),Math.max(0,e));try{t.start(),o?.()}catch(m){c({ok:!1,error:{code:"TRANSPORT_FAILED",cause:m}})}})}function kn(t){if(!(!Array.isArray(t)||t.length===0||t.length>bo||!Array.from(t).every(e=>Number.isSafeInteger(e)&&e>0)||new Set(t).size!==t.length))return[...t].sort((e,n)=>e-n)}function Ro(t,e){let n=t.filter(c=>e.includes(c));if(n.length>0)return{ok:!0,value:Math.max(...n)};let o=Math.min(...t),i=Math.max(...t),s=Math.min(...e),d=Math.max(...e);return i<s?{ok:!1,error:{code:"APP_PROTOCOL_TOO_OLD",appProtocols:t,hostProtocols:e}}:d<o?{ok:!1,error:{code:"HOST_PROTOCOL_TOO_OLD",appProtocols:t,hostProtocols:e}}:{ok:!1,error:{code:"PROTOCOL_INCOMPATIBLE",appProtocols:t,hostProtocols:e}}}async function Un(t,e,n,o){let i=kn(e);if(!i)return t.close(),{ok:!1,error:{code:"TRANSPORT_FAILED",cause:new Error("The app protocol registry is invalid.")}};let s=await yo(t,n,o,()=>{t.postMessage({namespace:Nn,version:Sn,type:"offer",role:"app",protocols:i})});if(t.close(),!s.ok)return s;let{data:d,ports:c}=s.value;if(!b(d)||d.namespace!==Nn||d.version!==Sn||d.type!=="answer"||d.role!=="host"){for(let C of c)C.close();return{ok:!1,error:{code:"TRANSPORT_FAILED",cause:new Error("The host returned an invalid compatibility answer.")}}}let h=kn(d.protocols);if(!h){for(let C of c)C.close();return{ok:!1,error:{code:"TRANSPORT_FAILED",cause:new Error("The host returned an invalid supported-protocol list.")}}}let f=Ro(i,h);if(!f.ok){for(let C of c)C.close();return f}let[m]=c;if(c.length!==1||m===void 0){for(let C of c)C.close();return{ok:!1,error:{code:"TRANSPORT_FAILED",cause:new Error("A compatible host must transfer exactly one operational port.")}}}return{ok:!0,value:{protocol:f.value,operationalPort:m}}}import{connect as ko,PortMessenger as Uo,Reply as Vo}from"penpal";var pt="dd-apps-frontend-heartbeat",ht=1,Vn=Object.freeze({intervalMs:En,timeoutMs:Tn});function rt(t){try{t.postMessage({namespace:pt,version:ht,type:"close"})}catch{}}function Fn(t,e){rt(e),globalThis.setTimeout(()=>{w("failed Penpal connection",()=>t.destroy()),w("failed operational port",()=>e.close())},xe)}var K,re,ie,nt,Q,ot,V,Mt,Pt,wt,ft,mt=class{constructor(e,n,o,i){this.port=e;this.onDead=n;this.policy=o;this.side=i;p(this,V);p(this,K);p(this,re);p(this,ie,0);p(this,nt,!1);p(this,Q,!1);p(this,ot,e=>{let n=e.data;if(!(!b(n)||n.namespace!==pt||n.version!==ht)){if(n.type==="close"){a(this,V,ft).call(this,!1);return}if(k(n.nonce)){if(n.type==="ping"){try{this.port.postMessage({namespace:pt,version:ht,type:"pong",nonce:n.nonce})}catch(o){y("could not answer a heartbeat probe",{side:this.side,cause:S(o)}),a(this,V,ft).call(this,!0)}return}n.type!=="pong"||n.nonce!==r(this,re)||(l(this,re,void 0),l(this,ie,0),r(this,K)!==void 0&&(globalThis.clearTimeout(r(this,K)),l(this,K,void 0)),a(this,V,Mt).call(this,this.policy.intervalMs))}}});this.port.addEventListener("message",r(this,ot))}port;onDead;policy;side;start(){r(this,nt)||r(this,Q)||(l(this,nt,!0),a(this,V,Mt).call(this,this.policy.intervalMs))}stop(){r(this,Q)||(l(this,Q,!0),l(this,re,void 0),r(this,K)!==void 0&&(globalThis.clearTimeout(r(this,K)),l(this,K,void 0)),this.port.removeEventListener("message",r(this,ot)))}};K=new WeakMap,re=new WeakMap,ie=new WeakMap,nt=new WeakMap,Q=new WeakMap,ot=new WeakMap,V=new WeakSet,Mt=function(e){r(this,Q)||l(this,K,globalThis.setTimeout(()=>a(this,V,Pt).call(this),Math.max(0,e)))},Pt=function(){if(r(this,Q))return;let e=me("heartbeat");l(this,re,e);try{this.port.postMessage({namespace:pt,version:ht,type:"ping",nonce:e})}catch(n){x("could not send a heartbeat probe",{side:this.side,misses:r(this,ie),cause:S(n)}),a(this,V,wt).call(this,e);return}l(this,K,globalThis.setTimeout(()=>a(this,V,wt).call(this,e),Math.max(0,this.policy.timeoutMs)))},wt=function(e){if(!(r(this,Q)||r(this,re)!==e)){if(l(this,re,void 0),l(this,ie,r(this,ie)+1),r(this,ie)>=2){y("the peer stopped answering heartbeats",{side:this.side,misses:r(this,ie),probeTimeoutMs:this.policy.timeoutMs,intervalMs:this.policy.intervalMs}),a(this,V,ft).call(this,!0);return}x("a heartbeat probe went unanswered",{side:this.side,misses:r(this,ie),probeTimeoutMs:this.policy.timeoutMs}),a(this,V,Pt).call(this)}},ft=function(e){r(this,Q)||(this.stop(),this.onDead(e))};import{Reply as vo}from"penpal";function Ao(t){return(typeof t=="object"&&t!==null||typeof t=="function")&&typeof t.then=="function"}function De(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=1}function Nt(t){return Array.isArray(t)&&t.every(De)}function Me(t){return Array.isArray(t)&&t.every(e=>typeof e=="number"&&Number.isSafeInteger(e)&&e>0)}function Io(t){return Array.isArray(t)&&t.every(e=>typeof e=="string"||typeof e=="number"&&Number.isSafeInteger(e)&&e>=0)}function St(t){return Array.isArray(t)&&t.every(e=>b(e)&&typeof e.message=="string"&&Io(e.path))}function Pe(t,e){try{let n=t["~standard"].validate(e);return Ao(n)?(Promise.resolve(n).catch(()=>{}),u([{message:"Embedding value schemas must be synchronous.",path:[]}])):n.issues?u(n.issues.map(o=>({message:o.message,path:_o(o.path)}))):P(n.value)}catch(n){return u([{message:n instanceof Error?n.message:"The value parser rejected this value.",path:[]}])}}function _o(t){return t?t.map(e=>{let n=typeof e=="object"&&e!==null&&"key"in e?e.key:e;return typeof n=="string"||typeof n=="number"&&Number.isSafeInteger(n)&&n>=0?n:String(n)}):[]}function it(t,e=[],n=new Set){try{globalThis.structuredClone(t);return}catch{if(typeof t!="object"&&typeof t!="function"||t===null||n.has(t))return e;n.add(t);let o;try{o=Object.entries(t)}catch{return e}for(let[i,s]of o){let d=it(s,[...e,Array.isArray(t)?Number(i):i],n);if(d)return d}return e}}function He(t,e){return e.map(n=>({message:n.message,path:[t,...n.path]}))}function gt(t){return Object.entries(t.fields).filter(([,e])=>e.kind==="value").map(([e])=>e)}function xn(t,e,n){let o=new Set(t);if(n){let s=[...o].find(d=>!Object.prototype.hasOwnProperty.call(e,d));if(s!==void 0)return{field:s,kind:"missing"}}let i=Object.keys(e).find(s=>!o.has(s));return i===void 0?void 0:{field:i,kind:"unknown"}}function Hn(t){return{code:"INVALID_RESULT",issues:[{message:t.kind==="missing"?"The host value snapshot omitted a claimed field.":"The host value snapshot included an unclaimed field.",path:[t.field]}]}}function Et(t,e){let n=xn(t,e,!0);return n&&Hn(n)}function kt(t,e){let n=xn(t,e,!1);return n&&Hn(n)}function Ut(t,e,n){let o;try{o=n.get()}catch(s){return y("a host value provider threw while being read",{side:"host",field:t,cause:S(s)}),u([{message:"The host value provider threw while being read.",path:[t]}])}let i=Pe(e,o);if(!i.ok)return u(He(t,i.error));try{return P(globalThis.structuredClone(i.value))}catch{let s=it(i.value)??[];return u([{message:"The host value is not structured-clone-safe.",path:[t,...s]}])}}function Tt(t,e,n){return y("a host value could not be provided",{side:"host",target:`${t}.${e}`,details:S(n)}),[{message:"The host could not provide a value that satisfies this field schema.",path:[e]}]}function Vt(t,e,n){if(!b(n))return u([{message:"Expected a named inputs object.",path:[t,"inputs"]}]);let o=Object.keys(n).find(s=>!Object.hasOwn(e.inputs,s));if(o!==void 0)return u([{message:`Unknown function input "${o}".`,path:[t,"inputs",o]}]);let i=Object.create(null);for(let[s,d]of Object.entries(e.inputs)){let c=Pe(d,Object.hasOwn(n,s)?n[s]:void 0);if(!c.ok)return u(c.error.map(h=>({message:h.message,path:[t,"inputs",s,...h.path]})));i[s]=c.value}try{return P(globalThis.structuredClone(i))}catch{let s=it(i)??[];return u([{message:"The function inputs are not structured-clone-safe.",path:[t,"inputs",...s]}])}}function jn(t){if(typeof t!="object"||t===null||typeof globalThis.MessagePort!="function")return!1;if(t instanceof globalThis.MessagePort)return!0;let e=globalThis.MessagePort.prototype;for(;e;){let n=Object.getOwnPropertyDescriptor(e,"onmessage")?.get;if(n)try{return n.call(t),!0}catch{return!1}e=Object.getPrototypeOf(e)}return!1}var Bn=Object.freeze({"~standard":{version:1,vendor:"@datadog/apps-frontend",validate(t){return jn(t)?{value:t}:{issues:[{message:"Expected a MessagePort."}]}}}});function st(t){jn(t)&&w("discarded function result MessagePort",()=>t.close())}function Lt(t,e=[]){return u([{message:"The function result is not structured-clone-safe.",path:[t,...e]}])}function zn(t,e,n){let o=Pe(e.result,n);if(!o.ok)return u(He(t,o.error));if(e.result===Bn){let i=o.value;try{let s=globalThis.structuredClone(i,{transfer:[i]});return P(new vo(P(s),{transferables:[s]}))}catch{return Lt(t)}}try{return P(P(globalThis.structuredClone(o.value)))}catch{let i=it(o.value)??[];return Lt(t,i)}}function Wn(t,e,n){let o=Pe(e.result,n);if(!o.ok)return u(He(t,o.error));if(e.result===Bn)return P(o.value);try{return P(globalThis.structuredClone(o.value))}catch{let i=it(o.value)??[];return Lt(t,i)}}import{ErrorCode as Do,PenpalError as Mo}from"penpal";function Po(t){let e=t.wanted,n=t.hostVersions;return De(e)&&Nt(n)&&!n.includes(e)&&n.some(o=>o>e)}function wo(t){let e=t.wanted,n=t.hostVersions;return De(e)&&Nt(n)&&!n.includes(e)&&n.every(o=>o<e)}var $n={ORIGIN_REJECTED:t=>typeof t.origin=="string",APP_PROTOCOL_TOO_OLD:t=>Me(t.appProtocols)&&Me(t.hostProtocols),HOST_PROTOCOL_TOO_OLD:t=>Me(t.appProtocols)&&Me(t.hostProtocols),PROTOCOL_INCOMPATIBLE:t=>Me(t.appProtocols)&&Me(t.hostProtocols),PEER_LACKS_MODULE:t=>typeof t.identifier=="string",APP_MAJOR_TOO_OLD:Po,HOST_MAJOR_TOO_OLD:wo,CONTRACT_INCOMPATIBLE:t=>typeof t.field=="string",INVALID_ARGUMENT:t=>St(t.issues),FUNCTION_FAILED:t=>typeof t.field=="string",INVALID_RESULT:t=>St(t.issues),TIMED_OUT:t=>typeof t.timeoutMs=="number"&&Number.isFinite(t.timeoutMs)&&t.timeoutMs>=0,TRANSPORT_FAILED:()=>!0,ABORTED:()=>!0,DISCONNECTED:()=>!0,UNRECOGNIZED:t=>typeof t.rawCode=="string"&&t.rawCode.length>0},Lo={ORIGIN_REJECTED:["origin"],APP_PROTOCOL_TOO_OLD:["appProtocols","hostProtocols"],HOST_PROTOCOL_TOO_OLD:["appProtocols","hostProtocols"],PROTOCOL_INCOMPATIBLE:["appProtocols","hostProtocols"],PEER_LACKS_MODULE:["identifier"],APP_MAJOR_TOO_OLD:["wanted","hostVersions"],HOST_MAJOR_TOO_OLD:["wanted","hostVersions"],CONTRACT_INCOMPATIBLE:["field"],INVALID_ARGUMENT:["issues"],FUNCTION_FAILED:["field"],INVALID_RESULT:["issues"],TIMED_OUT:["timeoutMs"],TRANSPORT_FAILED:[],ABORTED:[],DISCONNECTED:[],UNRECOGNIZED:["rawCode","raw"]};function Ct(t,e){if(b(t)&&typeof t.code=="string"){let n=t.code;if(e.includes(n)&&Object.prototype.hasOwnProperty.call($n,n)){let o=$n[n];if(o(t)){if(n==="UNRECOGNIZED")return{code:n,rawCode:t.rawCode,raw:void 0};let i={code:n};for(let s of Lo[n])i[s]=t[s];return i}}}return{code:"UNRECOGNIZED",rawCode:b(t)&&typeof t.code=="string"?t.code:"MALFORMED_ERROR",raw:void 0}}function Ee(t,e,n){let o=`${t.identifier}.${e}`,i=n.code==="UNRECOGNIZED"?"UNKNOWN":n.code,s;switch(n.code){case"INVALID_ARGUMENT":s=`The inputs passed to "${o}" are invalid: ${n.issues[0]?.message??"the schema rejected them"}.`;break;case"INVALID_RESULT":s=`Datadog returned an invalid result from "${o}": ${n.issues[0]?.message??"the schema rejected it"}. The app and host may be using incompatible schema implementations.`;break;case"FUNCTION_FAILED":s=`Datadog could not complete "${o}". Screenshot this message and contact support if the problem continues.`;break;case"TIMED_OUT":s=`"${o}" did not finish within ${n.timeoutMs} ms. It may still complete in Datadog; do not automatically retry an action that is not idempotent.`;break;case"CONTRACT_INCOMPATIBLE":s=`The Datadog host contract for "${o}" does not match the schema compiled into this app. Update the app or contact support.`;break;case"ABORTED":s=`The inputs used by "${o}" were released before it completed. Its outcome is unknown; wait for the inputs to become ready before calling it again.`;break;case"DISCONNECTED":s=`The Datadog connection closed before "${o}" completed. Its outcome is unknown; reconnect before trying again.`;break;case"UNRECOGNIZED":s=`Datadog returned an unrecognized failure for "${o}" (${n.rawCode}). Screenshot this message and contact support.`;break;default:s=n}let d=new Error(`DATADOG_APP_INPUT_FUNCTION_${i}: ${s}`,{cause:n});return d.name="DatadogAppInputFunctionError",y("a Datadog host function call failed",{side:"app",target:o,error:J(n)}),Object.assign(d,{code:i})}function Gn(t,e){return b(t)&&t.code==="ABORTED"?{code:"ABORTED"}:b(t)&&t.code==="TIMED_OUT"?{code:"TIMED_OUT",timeoutMs:e}:b(t)&&t.code==="DISCONNECTED"?{code:"DISCONNECTED"}:t instanceof Mo&&t.code===Do.ConnectionTimeout?{code:"TIMED_OUT",timeoutMs:e}:{code:"TRANSPORT_FAILED",cause:t}}function Jn(t){if(!b(t))return{code:"INVALID_RESULT",issues:[{message:"Malformed __ddClaim envelope: expected an object.",path:[]}]};if(!k(t.claimId,B))return{code:"INVALID_RESULT",issues:[{message:`"claimId" must contain between 1 and ${B} characters.`,path:["claimId"]}]};if(!k(t.identifier))return{code:"INVALID_RESULT",issues:[{message:'"identifier" must be a non-empty string.',path:["identifier"]}]};if(!De(t.version))return{code:"INVALID_RESULT",issues:[{message:'"version" must be a positive integer.',path:["version"]}]};if(!Array.isArray(t.fields)||t.fields.length===0||t.fields.length>_t)return{code:"INVALID_RESULT",issues:[{message:`"fields" must contain between 1 and ${_t} entries.`,path:["fields"]}]};if(!t.fields.every(e=>typeof e=="string"&&e.length>0&&e.length<=Dt)||new Set(t.fields).size!==t.fields.length)return{code:"INVALID_RESULT",issues:[{message:`"fields" must contain unique non-empty strings of at most ${Dt} characters.`,path:["fields"]}]}}function Kn(t){if(!b(t))return{code:"INVALID_ARGUMENT",issues:[{message:"Malformed __ddCall envelope: expected an object.",path:[]}]};if(!k(t.claimId,B))return{code:"INVALID_ARGUMENT",issues:[{message:`"claimId" must contain between 1 and ${B} characters.`,path:["claimId"]}]};if(!k(t.callId,tt))return{code:"INVALID_ARGUMENT",issues:[{message:`"callId" must contain between 1 and ${tt} characters.`,path:["callId"]}]};if(!k(t.field))return{code:"INVALID_ARGUMENT",issues:[{message:'"field" must be a non-empty string.',path:["field"]}]};if(!b(t.inputs))return{code:"INVALID_ARGUMENT",issues:[{message:'"inputs" must be an object.',path:["inputs"]}]}}function Ft(t,e){let n=e.map(({version:s})=>s).sort((s,d)=>s-d),o=n[n.length-1];if(o===void 0)return u({code:"HOST_MAJOR_TOO_OLD",wanted:t,hostVersions:n});let i=e.find(({version:s})=>s===t);return i?P(i):u(t<o?{code:"APP_MAJOR_TOO_OLD",wanted:t,hostVersions:n}:{code:"HOST_MAJOR_TOO_OLD",wanted:t,hostVersions:n})}function Zn(t,e){let n=e.filter(({identifier:i})=>i===t.identifier);if(n.length===0)return{code:"PEER_LACKS_MODULE",identifier:t.identifier};let o=Ft(t.version,n);return o.ok?void 0:o.error}var Le,Ht=class{constructor(e){this.value=e;p(this,Le,new Set)}value;get(){return this.value}subscribe(e){return r(this,Le).add(e),()=>{r(this,Le).delete(e)}}set(e){return Object.is(this.value,e)?!1:(this.value=e,!0)}notify(){ge(r(this,Le))}freeze(){r(this,Le).clear()}};Le=new WeakMap;var xt=0;function Xn(t){let e=t.timeoutMs;return typeof e=="number"&&Number.isFinite(e)&&e>0&&e<=2147483647?e:6e5}var at,F,se,Te,Ce,Z,q,Oe,Be,ze,dt,I,jt,we,Ot,je,Bt,bt=class{constructor(e,n,o,i,s,d){this.role=e;this.remote=n;this.penpal=o;this.port=i;this.modules=s;this.operationTimeoutMs=d;p(this,I);p(this,at,new AbortController);p(this,F,new Map);p(this,se,new Map);p(this,Te,new Map);p(this,Ce,new Map);p(this,Z,new Map);p(this,q,new Map);p(this,Oe,new Set);p(this,Be);p(this,ze,!1);p(this,dt,!1)}role;remote;penpal;port;modules;operationTimeoutMs;get closed(){return r(this,ze)}get closeSignal(){return r(this,at).signal}attachHeartbeat(e){if(this.closed){e.stop();return}l(this,Be,e),e.start()}send(e,n){if(this.closed)return;let o;try{o=n()}catch(d){y("an outbound embedding message could not be sent",{side:this.role,operation:e,cause:S(d)}),this.noteDisconnected();return}let i=globalThis.setTimeout(()=>{r(this,Oe).delete(i),y("an outbound embedding message was never acknowledged; closing the connection",{side:this.role,operation:e,timeoutMs:this.operationTimeoutMs}),this.close()},Math.max(0,this.operationTimeoutMs));r(this,Oe).add(i);let s=(d,c)=>{r(this,Oe).delete(i)&&(globalThis.clearTimeout(i),d&&(y("an outbound embedding message was rejected",{side:this.role,operation:e,cause:S(c)}),this.noteDisconnected()))};o.then(()=>s(!1),d=>s(!0,d))}noteDisconnected(e=!1){this.close(e)}close(e=!0){if(r(this,ze))return;l(this,ze,!0);let n;if(e){rt(this.port);try{n=this.remote.__ddClose()}catch{}}r(this,Be)?.stop(),l(this,Be,void 0);for(let o of r(this,Oe))globalThis.clearTimeout(o);r(this,Oe).clear(),r(this,at).abort();for(let o of[...r(this,F).keys()])this.receiveRelease(o);for(let[o,i]of[...r(this,Te).entries()])a(this,I,je).call(this,o,i,{code:"DISCONNECTED"},!1);if(r(this,Ce).clear(),r(this,Z).clear(),r(this,q).clear(),!e){a(this,I,jt).call(this);return}n?.catch(()=>{}),globalThis.setTimeout(()=>a(this,I,jt).call(this),xe)}async settleRemoteResult(e,n){return this.closed?(e.then(o=>{n.onDiscardedResult?.(o)},()=>{}),u(n.disconnectedError)):new Promise(o=>{let i=!1,s,d=f=>{i||(i=!0,s!==void 0&&globalThis.clearTimeout(s),n.signal?.removeEventListener("abort",c),this.closeSignal.removeEventListener("abort",h),o(f))},c=()=>{n.onCancel(),d(u(n.abortError))},h=()=>d(u(n.disconnectedError));if(n.signal?.addEventListener("abort",c,{once:!0}),this.closeSignal.addEventListener("abort",h,{once:!0}),n.signal?.aborted){c();return}if(this.closeSignal.aborted){h();return}s=globalThis.setTimeout(()=>{n.onCancel(),d(u(n.timeoutError(n.timeoutMs)))},Math.max(0,n.timeoutMs)),e.then(f=>{if(i){n.onDiscardedResult?.(f);return}if(b(f)&&f.ok===!0){d(P(f.value));return}n.onDiscardedResult?.(f),d(u(n.normalize(b(f)?f.error:f)))},()=>{this.noteDisconnected(),d(u(n.disconnectedError))})})}async claim(e,n={}){if(this.closed)return u({code:"DISCONNECTED"});if(n.signal?.aborted)return u({code:"ABORTED"});let o=n.timeoutMs??5e3;qe("ClaimOptions.timeoutMs",o);let i=me("claim");r(this,Ce).set(i,e);let s;try{s=this.remote.__ddClaim({claimId:i,identifier:e.identifier,version:e.version,fields:Object.keys(e.fields)})}catch(O){return y("a claim could not be sent to the Datadog host",{side:this.role,claimId:i,identifier:e.identifier,version:e.version,cause:S(O)}),a(this,I,we).call(this,i),this.noteDisconnected(),u({code:"DISCONNECTED"})}s=s.then(O=>O,()=>(this.noteDisconnected(),u({code:"DISCONNECTED"})));let d=await this.settleRemoteResult(s,{timeoutMs:o,signal:n.signal,onCancel:()=>{this.send("__ddRelease",()=>this.remote.__ddRelease(i))},timeoutError:O=>({code:"TIMED_OUT",timeoutMs:O}),abortError:{code:"ABORTED"},disconnectedError:{code:"DISCONNECTED"},normalize:O=>Ct(O,["PEER_LACKS_MODULE","APP_MAJOR_TOO_OLD","HOST_MAJOR_TOO_OLD","CONTRACT_INCOMPATIBLE","INVALID_RESULT","TIMED_OUT","ABORTED","DISCONNECTED","UNRECOGNIZED"])});if(!d.ok)return a(this,I,we).call(this,i),d;if(!b(d.value)||!b(d.value.values))return a(this,I,we).call(this,i),this.send("__ddRelease",()=>this.remote.__ddRelease(i)),u({code:"INVALID_RESULT",issues:[{message:"Malformed claim success payload.",path:[]}]});let c=Et(gt(e),d.value.values);if(c)return a(this,I,we).call(this,i),this.send("__ddRelease",()=>this.remote.__ddRelease(i)),u(c);let h=new Map,f={},m={contract:e,values:h,valueListeners:new Set,invalidationListeners:new Set,releaseController:new AbortController,released:!1,hydrated:!1};for(let[O,D]of Object.entries(e.fields)){if(D.kind==="function"){f[O]=(...T)=>this.callFunction(i,m,O,D,T);continue}let H=Pe(D.schema,d.value.values[O]);if(!H.ok)return a(this,I,we).call(this,i),this.send("__ddRelease",()=>this.remote.__ddRelease(i)),u({code:"INVALID_RESULT",issues:He(O,H.error)});let M=new Ht(H.value);h.set(O,M),f[O]=M}r(this,Te).set(i,m);let C=r(this,Z).get(i);C&&this.receiveValues(i,C);let _=m.invalidation??r(this,q).get(i);return a(this,I,we).call(this,i),_?(a(this,I,Ot).call(this,i,m,!0,_),u(_)):P({fields:f,release:()=>a(this,I,Ot).call(this,i,m,!0),onValuesChanged:O=>m.released?()=>{}:(m.valueListeners.add(O),()=>m.valueListeners.delete(O)),onInvalidated:O=>{let D=m.invalidation;return D?(globalThis.queueMicrotask(()=>O(D)),()=>{}):m.released?()=>{}:(m.invalidationListeners.add(O),()=>m.invalidationListeners.delete(O))}})}async callFunction(e,n,o,i,s){if(this.closed)throw Ee(n.contract,o,{code:"DISCONNECTED"});if(n.released)throw Ee(n.contract,o,{code:"ABORTED"});if(s.length!==1)throw Ee(n.contract,o,{code:"INVALID_ARGUMENT",issues:[{message:`Expected one named inputs object, received ${s.length} arguments.`,path:[o,"inputs"]}]});let d=Vt(o,i,s[0]);if(!d.ok)throw Ee(n.contract,o,{code:"INVALID_ARGUMENT",issues:d.error});let c=me("call"),h;try{h=this.remote.__ddCall({claimId:e,callId:c,field:o,inputs:d.value})}catch{throw this.noteDisconnected(),Ee(n.contract,o,{code:"DISCONNECTED"})}let f=await this.settleRemoteResult(h,{timeoutMs:Xn(i),signal:n.releaseController.signal,onCancel:()=>{this.send("__ddCancel",()=>this.remote.__ddCancel({claimId:e,callId:c}))},timeoutError:C=>({code:"TIMED_OUT",timeoutMs:C}),abortError:{code:"ABORTED"},disconnectedError:{code:"DISCONNECTED"},normalize:C=>Ct(C,["CONTRACT_INCOMPATIBLE","INVALID_ARGUMENT","FUNCTION_FAILED","INVALID_RESULT","TIMED_OUT","ABORTED","DISCONNECTED","UNRECOGNIZED"]),onDiscardedResult:C=>{b(C)&&C.ok===!0&&st(C.value)}});if(!f.ok){let C=f.error.code==="INVALID_ARGUMENT"?{code:"CONTRACT_INCOMPATIBLE",field:o}:f.error;throw Ee(n.contract,o,C)}let m=Wn(o,i,f.value);if(!m.ok)throw Ee(n.contract,o,{code:"INVALID_RESULT",issues:m.error});return m.value}receiveValues(e,n){if(!k(e,B)){y("ignored a __ddValues envelope with an invalid claim id",{side:this.role,claimId:e,maxClaimIdLength:B});return}let o=r(this,Te).get(e),i=r(this,Ce).get(e);if(!b(n)){let h={code:"INVALID_RESULT",issues:[{message:"The host value snapshot must be an object.",path:[]}]};o?a(this,I,je).call(this,e,o,h,!0):i?(r(this,q).set(e,h),r(this,Z).delete(e)):y("ignored a __ddValues envelope for an unknown claim",{side:this.role,claimId:e,receivedValues:typeof n});return}if(!o){if(!i)return;let f=r(this,Z).has(e)?kt(gt(i),n):Et(gt(i),n);if(f){r(this,q).set(e,f),r(this,Z).delete(e);return}if(!r(this,q).has(e)){let m=r(this,Z).get(e);r(this,Z).set(e,Object.freeze({...m,...n}))}return}let s=o.hydrated?kt(o.values.keys(),n):Et(o.values.keys(),n);if(s){a(this,I,je).call(this,e,o,s,!0);return}o.hydrated=!0;let d=[];for(let[h,f]of Object.entries(n)){let m=o.values.get(h),C=o.contract.fields[h];if(!m||!C||C.kind!=="value")continue;let _=Pe(C.schema,f);if(!_.ok){let O={code:"INVALID_RESULT",issues:He(h,_.error)};a(this,I,je).call(this,e,o,O,!0);return}d.push([m,_.value])}let c=[];for(let[h,f]of d)h.set(f)&&c.push(h);for(let h of c)h.notify();c.length>0&&ge(o.valueListeners)}receiveInvalidation(e,n){if(!k(e,B)){y("ignored a __ddInvalidate envelope with an invalid claim id",{side:this.role,claimId:e,maxClaimIdLength:B});return}let o=Ct(n,["INVALID_RESULT","UNRECOGNIZED"]),i=r(this,Te).get(e);if(i){a(this,I,je).call(this,e,i,o,!1);return}r(this,Ce).has(e)&&r(this,q).set(e,o)}async receiveClaim(e){if(this.closed)return u({code:"DISCONNECTED"});let n=Jn(e);if(n)return u(n);if(r(this,F).has(e.claimId))return u({code:"INVALID_RESULT",issues:[{message:`Claim id "${e.claimId}" is already live.`,path:["claimId"]}]});if(r(this,F).size>=It)return u({code:"INVALID_RESULT",issues:[{message:`The peer exceeded the limit of ${It} simultaneous claims.`,path:["claimId"]}]});let o=this.modules.filter(({contract:T})=>T.identifier===e.identifier);if(o.length===0)return u({code:"PEER_LACKS_MODULE",identifier:e.identifier});let i=Ft(e.version,o.map(T=>({version:T.contract.version,module:T})));if(!i.ok)return i;let s=i.value.module;if(s.signal?.aborted)return u({code:"INVALID_RESULT",issues:[{message:`The host provider for "${e.identifier}" is disposed.`,path:[]}]});let d=new Map,c={releases:[],module:s,fields:d};if(r(this,F).set(e.claimId,c),s.signal){let T=()=>a(this,I,Bt).call(this,e.claimId,[{message:`The host provider for "${e.identifier}" was disposed.`,path:[]}]);s.signal.addEventListener("abort",T,{once:!0}),c.releases.push(()=>s.signal?.removeEventListener("abort",T))}let h={},f={ready:!1},m=!1,C=!1,_=!1,O=new Set,D=new Map,H=()=>{if(C=!1,!r(this,F).has(e.claimId))return;let T=!_;if(!T&&O.size===0)return;let A=T?[...D.keys()]:[...O];_=!0,O.clear();let U={};for(let W of A){let oe=D.get(W);if(!oe)continue;let j=Ut(W,oe.field.schema,oe.provider);if(!j.ok){a(this,I,Bt).call(this,e.claimId,Tt(e.identifier,W,j.error));return}U[W]=j.value}this.send("__ddValues",()=>this.remote.__ddValues(e.claimId,U))},M=()=>{if(r(this,F).has(e.claimId)){if(!f.ready){m=!0;return}C||(C=!0,globalThis.queueMicrotask(H))}};for(let T of e.fields){let A=s.contract.fields[T];if(!A)return this.receiveRelease(e.claimId),u({code:"CONTRACT_INCOMPATIBLE",field:T});if(d.set(T,A),A.kind==="function"){let j=Object.hasOwn(s.implementation,T)?s.implementation[T]:void 0;if(!b(j)||typeof j.invoke!="function")return this.receiveRelease(e.claimId),u({code:"INVALID_RESULT",issues:[{message:"The host implementation is not a callable function field.",path:[T]}]});continue}let U=Object.hasOwn(s.implementation,T)?s.implementation[T]:void 0;if(!U||typeof U.get!="function"||typeof U.subscribe!="function")return this.receiveRelease(e.claimId),u({code:"INVALID_RESULT",issues:[{message:"The host implementation is not a live value.",path:[T]}]});D.set(T,{field:A,provider:U});let W;try{W=U.subscribe(()=>{O.add(T),M()})}catch(j){return this.receiveRelease(e.claimId),u({code:"INVALID_RESULT",issues:Tt(e.identifier,T,j)})}if(typeof W!="function")return this.receiveRelease(e.claimId),u({code:"INVALID_RESULT",issues:[{message:"The host value provider did not return an unsubscribe function.",path:[T]}]});if(r(this,F).get(e.claimId)!==c)return w(`unsubscribe for interrupted claim ${e.claimId}`,W),this.closed?u({code:"DISCONNECTED"}):u({code:"INVALID_RESULT",issues:[{message:`The host provider for "${e.identifier}" was disposed during claim setup.`,path:[]}]});c.releases.push(W);let oe=Ut(T,A.schema,U);if(!oe.ok)return this.receiveRelease(e.claimId),u({code:"INVALID_RESULT",issues:Tt(e.identifier,T,oe.error)});h[T]=oe.value}return f.ready=!0,m&&M(),P({values:h})}async receiveFunctionCall(e){if(this.closed)return u({code:"DISCONNECTED"});let n=Kn(e);if(n)return u(n);let o=r(this,F).get(e.claimId);if(!o)return u({code:"DISCONNECTED"});let i=o.fields.get(e.field);if(!i||i.kind!=="function")return u({code:"CONTRACT_INCOMPATIBLE",field:e.field});if(r(this,se).has(e.callId))return u({code:"INVALID_ARGUMENT",issues:[{message:`Function call id "${e.callId}" is already active.`,path:["callId"]}]});if(xt>=bn)return u({code:"FUNCTION_FAILED",field:e.field});let s=Vt(e.field,i,e.inputs);if(!s.ok)return y("the host rejected the inputs of a function call",{side:this.role,claimId:e.claimId,callId:e.callId,target:`${o.module.contract.identifier}.${e.field}`,issueCount:s.error.length}),u({code:"INVALID_ARGUMENT",issues:[{message:"The function inputs do not satisfy the host schema.",path:[e.field,"inputs"]}]});let d=Object.hasOwn(o.module.implementation,e.field)?o.module.implementation[e.field]:void 0;if(!b(d)||typeof d.invoke!="function")return u({code:"CONTRACT_INCOMPATIBLE",field:e.field});let c=new AbortController,h=()=>{},f=new Promise(A=>{h=A}),m={claimId:e.claimId,controller:c,interrupt(A){c.signal.aborted||(c.abort(),h({status:"interrupted",reason:A}))}};xt+=1,r(this,se).set(e.callId,m);let C=Xn(i),_=globalThis.performance.now()+C,O=globalThis.setTimeout(()=>m.interrupt("timed-out"),C),D;try{let A=d.invoke(s.value,Object.freeze({signal:c.signal}));globalThis.performance.now()>=_&&m.interrupt("timed-out"),D=Promise.resolve(A).then(U=>globalThis.performance.now()>=_?(m.interrupt("timed-out"),st(U),{status:"interrupted",reason:"timed-out"}):{status:"returned",value:U},U=>globalThis.performance.now()>=_?(m.interrupt("timed-out"),{status:"interrupted",reason:"timed-out"}):{status:"threw",cause:U})}catch(A){globalThis.performance.now()>=_&&m.interrupt("timed-out"),D=Promise.resolve({status:"threw",cause:A})}let H=D.finally(()=>{xt-=1,r(this,se).get(e.callId)===m&&r(this,se).delete(e.callId)}),M=await Promise.race([H,f]);if(globalThis.clearTimeout(O),M.status==="interrupted")return H.then(A=>{A.status==="returned"&&st(A.value)}),M.reason==="timed-out"?u({code:"TIMED_OUT",timeoutMs:C}):u({code:"DISCONNECTED"});if(this.closed||c.signal.aborted||r(this,F).get(e.claimId)!==o)return M.status==="returned"&&st(M.value),u({code:"DISCONNECTED"});if(M.status==="threw")return y("a host function implementation threw",{side:this.role,claimId:e.claimId,callId:e.callId,target:`${o.module.contract.identifier}.${e.field}`,cause:S(M.cause)}),u({code:"FUNCTION_FAILED",field:e.field});let T=zn(e.field,i,M.value);return T.ok?T.value:(y("a host function returned an invalid result",{side:this.role,claimId:e.claimId,callId:e.callId,target:`${o.module.contract.identifier}.${e.field}`,issues:T.error}),u({code:"INVALID_RESULT",issues:[{message:"The host function returned a result that does not satisfy its schema.",path:[e.field]}]}))}receiveFunctionCancel(e){if(!b(e)||!k(e.claimId,B)||!k(e.callId,tt)){y("ignored a malformed __ddCancel envelope",{side:this.role,request:b(e)?{claimId:e.claimId,callId:e.callId}:{malformed:!0,received:typeof e}});return}let n=r(this,se).get(e.callId);n?.claimId===e.claimId&&n.interrupt("cancelled")}receiveRelease(e){if(!k(e,B)){y("ignored a __ddRelease with an invalid claim id",{side:this.role,claimId:e,maxClaimIdLength:B});return}let n=r(this,F).get(e);if(n){r(this,F).delete(e);for(let o of r(this,se).values())o.claimId===e&&o.interrupt("cancelled");for(let o of n.releases)w(`unsubscribe for claim ${e}`,o)}}};at=new WeakMap,F=new WeakMap,se=new WeakMap,Te=new WeakMap,Ce=new WeakMap,Z=new WeakMap,q=new WeakMap,Oe=new WeakMap,Be=new WeakMap,ze=new WeakMap,dt=new WeakMap,I=new WeakSet,jt=function(){r(this,dt)||(l(this,dt,!0),w("Penpal connection",()=>this.penpal.destroy()),w("operational port",()=>this.port.close()))},we=function(e){r(this,Ce).delete(e),r(this,Z).delete(e),r(this,q).delete(e)},Ot=function(e,n,o,i){if(n.released)return!1;n.released=!0,n.invalidation=i,n.releaseController.abort();for(let s of n.values.values())s.freeze();return n.valueListeners.clear(),n.invalidationListeners.clear(),r(this,Te).delete(e),o&&this.send("__ddRelease",()=>this.remote.__ddRelease(e)),!0},je=function(e,n,o,i){let s=[...n.invalidationListeners];if(!a(this,I,Ot).call(this,e,n,i,o))return;(o.code==="DISCONNECTED"?x:y)("a live claim was invalidated",{side:this.role,claimId:e,identifier:n.contract.identifier,version:n.contract.version,observedListeners:s.length,error:J(o)}),ge(s,o)},Bt=function(e,n){let o=r(this,F).get(e);o&&(y("the host invalidated a claim it was serving",{side:this.role,claimId:e,identifier:o.module.contract.identifier,version:o.module.contract.version,issues:n}),this.receiveRelease(e),this.send("__ddInvalidate",()=>this.remote.__ddInvalidate(e,{code:"INVALID_RESULT",issues:n})))};function Fo(t,e){if(!b(t))return{malformed:!0,received:typeof t};let n={};for(let o of e)n[o]=t[o];return n}var Wt=class{constructor(e,n){this.endpoint=e;this.modules=n}endpoint;modules;async claim(e,n){if(this.endpoint.closed||n?.signal?.aborted)return this.endpoint.claim(e,n);qe("ClaimOptions.timeoutMs",n?.timeoutMs??5e3);let o=Zn(e,this.modules);return o?Promise.resolve(u(o)):this.endpoint.claim(e,n)}};function xo(t){return b(t)&&t.role==="host"&&Array.isArray(t.modules)}function Ho(t){let e=new Set,n=[];for(let o of t){if(!b(o)||!k(o.identifier)||!De(o.version))continue;let i=JSON.stringify([o.identifier,o.version]);e.has(i)||(e.add(i),n.push({identifier:o.identifier,version:o.version}))}return n}async function jo(t,e,n,o,i,s,d){let c,h,f=!1,m=!1,C,_=new Promise((g,R)=>{C=R});try{h=new mt(t,g=>{c?c.noteDisconnected(g):(f=!0,g||t.close(),C?.({code:"DISCONNECTED"}))},d,e)}catch(g){return w("failed operational port",()=>t.close()),u({code:"TRANSPORT_FAILED",cause:g})}let O=!1,D=0,H=()=>{},M=new Promise(g=>{H=g}),T=g=>{O||(O=!0,H(g))},A=(g,R)=>{let N=Y=>(x("an embedding operation was refused",{side:e,operation:R,expectedRole:g,reason:Y,pendingEndpointOperations:D}),new Error(Y));return c?c.role===g?Promise.resolve(c):Promise.reject(N("The embedding operation is not valid here.")):O||D>=yn?Promise.reject(N("The embedding endpoint is not ready for work.")):(D+=1,M.then(Y=>{if(!Y||Y.role!==g)throw N("The embedding operation is not valid here.");return Y}).finally(()=>{D-=1}))},U=e==="host"?{role:"host",modules:i.map(({contract:g})=>({identifier:g.identifier,version:g.version})),surfaceId:s}:{role:"app"},W=(g,R,N,Y)=>(Y.ok||x(`${g} was rejected`,{side:e,request:Fo(R,N),error:J(Y.error)}),Y),oe={__ddDescribe:()=>U,__ddClaim:g=>A("host","__ddClaim").then(R=>R.receiveClaim(g).then(N=>W("__ddClaim",g,["claimId","identifier","version","fields"],N))),__ddRelease:g=>A("host","__ddRelease").then(R=>R.receiveRelease(g)),__ddValues:(g,R)=>A("app","__ddValues").then(N=>N.receiveValues(g,R)),__ddCall:g=>A("host","__ddCall").then(R=>R.receiveFunctionCall(g).then(N=>(W("__ddCall",g,["claimId","callId","field"],N instanceof Vo?N.value:N),N))),__ddCancel:g=>A("host","__ddCancel").then(R=>R.receiveFunctionCancel(g)),__ddInvalidate:(g,R)=>A("app","__ddInvalidate").then(N=>N.receiveInvalidation(g,R)),__ddClose:()=>(c||(m=!0),A(e,"__ddClose").then(g=>g.close(!1)))},j;try{j=ko({messenger:new Uo({port:t}),methods:oe,timeout:n})}catch(g){return h.stop(),rt(t),globalThis.setTimeout(()=>t.close(),xe),u({code:"TRANSPORT_FAILED",cause:g})}let un,pn,hn=()=>un?.({code:"ABORTED"}),fn=new Promise((g,R)=>{un=R}),mn=new Promise((g,R)=>{pn=R}),mo=globalThis.setTimeout(()=>pn?.({code:"TIMED_OUT"}),Math.max(0,n));o.addEventListener("abort",hn,{once:!0});let At="handshake";try{if(o.aborted)throw Object.assign(new Error("The connection was aborted."),{code:"ABORTED"});let g=await Promise.race([j.promise,fn,mn,_]);At="peer-description";let R=await Promise.race([g.__ddDescribe(),fn,mn,_]);if(At="validation",!(e==="app"?xo(R):b(R)&&R.role==="app"))throw new Error(`Expected an embedding ${e==="app"?"host":"app"} using the operational protocol.`);if(c=new bt(e,g,j,t,i,n),f)throw Object.assign(new Error("The transport disconnected before establishment completed."),{code:"DISCONNECTED"});if(m)throw Object.assign(new Error("The peer requested to close before establishment completed."),{code:"DISCONNECTED"});return T(c),c.attachHeartbeat(h),P({endpoint:c,description:R})}catch(g){let R=Gn(g,n);return x("the operational protocol could not be established",{side:e,stage:At,timeoutMs:n,describedPeer:!!c,error:J(R),cause:S(g)}),h.stop(),c?c.close():Fn(j,t),u(R)}finally{T(void 0),globalThis.clearTimeout(mo),o.removeEventListener("abort",hn)}}function Bo(t){let e=t.endpoint,n=t.description;return{connection:new Wt(e,Ho(n.modules)),surfaceId:typeof n.surfaceId=="string"?n.surfaceId:void 0,closeSignal:e.closeSignal,close:()=>e.close()}}async function Yn(t,e,n,o){let i=await jo(t,"app",e,n,[],void 0,o);return i.ok?P(Bo(i.value)):i}var $o=[1];async function Go(t,e,n=1e4){if(e.aborted)return t.close(),u({code:"ABORTED"});let o=await Un(t,$o,n,e);return o.ok?Yn(o.value.operationalPort,n,e,Vn):o}var We,$t=class{constructor(){p(this,We)}next(){let e=r(this,We)??Cn;return l(this,We,Math.min(e*2,On)),e}reset(){l(this,We,void 0)}};We=new WeakMap;function Jo(){return typeof globalThis.window<"u"&&globalThis.window.parent!==globalThis.window}function Ko(t){switch(t.code){case"TIMED_OUT":case"TRANSPORT_FAILED":case"DISCONNECTED":case"UNRECOGNIZED":return!0;case"ORIGIN_REJECTED":case"APP_PROTOCOL_TOO_OLD":case"HOST_PROTOCOL_TOO_OLD":case"PROTOCOL_INCOMPATIBLE":case"ABORTED":return!1;default:return t}}var ae,Se,ct,z,de,ee,ce,le,te,be,$e,ke,v,Qn,Jt,Kt,Zt,Xt,yt,qn,Ne,Gt=class{constructor(){p(this,v);p(this,ae,new AbortController);p(this,Se,new Set);p(this,ct,new $t);p(this,z,{state:"connecting"});p(this,de);p(this,ee);p(this,ce);p(this,le);p(this,te);p(this,be,0);p(this,$e,!1);p(this,ke,!1);if(!Jo()){l(this,z,{state:"not-embedded"});return}a(this,v,Xt).call(this),a(this,v,Jt).call(this)}getSnapshot(){return r(this,z)}subscribe(e){return r(this,Se).add(e),()=>{r(this,Se).delete(e)}}close(){if(r(this,z).state==="closed")return;r(this,ae).abort(),r(this,ee)?.abort(),l(this,ee,void 0),a(this,v,Zt).call(this),a(this,v,yt).call(this);let e=r(this,de);l(this,de,void 0),a(this,v,Ne).call(this,{state:"closed"}),e?.close(),r(this,Se).clear()}};ae=new WeakMap,Se=new WeakMap,ct=new WeakMap,z=new WeakMap,de=new WeakMap,ee=new WeakMap,ce=new WeakMap,le=new WeakMap,te=new WeakMap,be=new WeakMap,$e=new WeakMap,ke=new WeakMap,v=new WeakSet,Qn=async function(e){let n=await wn(globalThis.window,Ln,e);return n.ok?Go(n.value,e):n},Jt=async function(){if(r(this,ae).signal.aborted||r(this,ke)||r(this,$e)||r(this,de))return;l(this,$e,!0),l(this,be,r(this,be)+1);let e=new AbortController;l(this,ee,e);let n;try{n=await a(this,v,Qn).call(this,e.signal)}catch(i){n={ok:!1,error:{code:"TRANSPORT_FAILED",cause:i}}}if(l(this,$e,!1),r(this,ee)===e&&l(this,ee,void 0),r(this,ae).signal.aborted||r(this,ke)){n.ok&&n.value.close();return}if(!n.ok){if(l(this,te,n.error),!Ko(n.error)){a(this,v,yt).call(this),y("the app connection was rejected",{side:"app",attempt:r(this,be),retryable:!1,error:J(n.error)}),a(this,v,Ne).call(this,{state:"rejected",error:n.error});return}a(this,v,Ne).call(this,r(this,z).state==="reconnecting"?{state:"reconnecting",lastError:n.error}:{state:"connecting",error:n.error}),a(this,v,Kt).call(this);return}l(this,de,n.value),l(this,te,void 0),r(this,ct).reset(),a(this,v,yt).call(this);let o=()=>{r(this,ae).signal.aborted||r(this,de)!==n.value||(l(this,de,void 0),l(this,te,{code:"DISCONNECTED"}),x("the app lost its established connection",{side:"app",attempt:r(this,be),surfaceId:n.value.surfaceId}),a(this,v,Xt).call(this),a(this,v,Ne).call(this,{state:"reconnecting",lastError:r(this,te)}),a(this,v,Kt).call(this))};if(n.value.closeSignal.addEventListener("abort",o,{once:!0}),n.value.closeSignal.aborted){o();return}a(this,v,Ne).call(this,{state:"connected",connection:n.value.connection,surfaceId:n.value.surfaceId})},Kt=function(){if(r(this,ae).signal.aborted||r(this,ke)||r(this,ce)!==void 0)return;let e=r(this,ct).next();x("retrying the app connection",{side:"app",state:r(this,z).state,failedAttempts:r(this,be),retryInMs:e,giveUpAfterMs:et,error:r(this,te)&&J(r(this,te))}),l(this,ce,globalThis.setTimeout(()=>{l(this,ce,void 0),a(this,v,Jt).call(this)},e))},Zt=function(){r(this,ce)!==void 0&&(globalThis.clearTimeout(r(this,ce)),l(this,ce,void 0))},Xt=function(){r(this,le)===void 0&&l(this,le,globalThis.setTimeout(()=>{l(this,le,void 0),a(this,v,qn).call(this)},et))},yt=function(){r(this,le)!==void 0&&(globalThis.clearTimeout(r(this,le)),l(this,le,void 0))},qn=function(){if(r(this,ae).signal.aborted||r(this,z).state==="connected"||r(this,z).state==="closed")return;l(this,ke,!0),a(this,v,Zt).call(this),r(this,ee)?.abort(),l(this,ee,void 0);let e=r(this,te)??{code:"TIMED_OUT",timeoutMs:et};y("the app gave up connecting to its Datadog host",{side:"app",state:r(this,z).state,failedAttempts:r(this,be),gaveUpAfterMs:et,error:J(e)}),a(this,v,Ne).call(this,{state:"rejected",error:e})},Ne=function(e){r(this,z)!==e&&(l(this,z,e),ge(r(this,Se)))};var eo=Object.freeze({connect(){return new Gt}});function to(t){return t.join(", ")}function Zo(t){return t.map(e=>`${e.path.length>0?e.path.join("."):"(root)"}: ${e.message}`).join("; ")}function Xo(t){let e;try{if(t instanceof Error)e=t.message||t.name;else if(typeof t=="string")e=t;else try{e=JSON.stringify(t)??String(t)}catch{e=Object.prototype.toString.call(t)}}catch{e="(cause could not be described)"}return e.length>200?`${e.slice(0,200)}\u2026`:e}function Yt(t){switch(t.code){case"TIMED_OUT":return{code:"TIMED_OUT",action:"retry",message:`TIMED_OUT: the Datadog host did not complete the connection within ${t.timeoutMs}ms. Reload the app to try again.`};case"ORIGIN_REJECTED":return{code:"ORIGIN_REJECTED",action:"contact-support",message:`ORIGIN_REJECTED: the embedding connection failed origin validation for "${t.origin}". Screenshot this message and contact support.`};case"APP_PROTOCOL_TOO_OLD":return{code:"APP_PROTOCOL_TOO_OLD",action:"update-app",message:`APP_PROTOCOL_TOO_OLD: this app supports embedding protocols ${t.appProtocols.join(", ")}, while the Datadog host requires ${t.hostProtocols.join(", ")}. Update @datadog/apps-frontend, rebuild this app, and upload the new bundle.`};case"HOST_PROTOCOL_TOO_OLD":return{code:"HOST_PROTOCOL_TOO_OLD",action:"contact-support",message:`HOST_PROTOCOL_TOO_OLD: this app supports embedding protocols ${t.appProtocols.join(", ")}, newer than the Datadog host's ${t.hostProtocols.join(", ")}. Rebuilding the app will not fix this; screenshot this message and contact support.`};case"PROTOCOL_INCOMPATIBLE":return{code:"PROTOCOL_INCOMPATIBLE",action:"contact-support",message:`PROTOCOL_INCOMPATIBLE: this app supports embedding protocols ${t.appProtocols.join(", ")}, while the Datadog host supports ${t.hostProtocols.join(", ")}. The sets do not overlap; screenshot this message and contact support.`};case"DISCONNECTED":return{code:"CONNECTION_LOST",action:"retry",message:"CONNECTION_LOST: the Datadog host stopped responding and the connection could not be re-established. Reload the app to try again."};case"TRANSPORT_FAILED":return{code:"UNKNOWN",action:"contact-support",message:`TRANSPORT_FAILED: the local embedding transport failed (${Xo(t.cause)}). Screenshot this message and contact support.`};case"UNRECOGNIZED":return{code:"UNKNOWN",action:"contact-support",message:`UNRECOGNIZED: the peer reported failure code "${t.rawCode}", which this app build does not know. Screenshot this message and contact support.`};case"ABORTED":return{code:"UNKNOWN",action:"contact-support",message:"ABORTED: the embedding connection was cancelled unexpectedly. Screenshot this message and contact support."};default:return t}}function Qt(t){switch(t.code){case"APP_MAJOR_TOO_OLD":return{code:"APP_MAJOR_TOO_OLD",action:"update-app",requestedVersion:t.wanted,availableVersions:t.hostVersions,message:`APP_MAJOR_TOO_OLD: this app's claim requests v${t.wanted}, while the host now offers ${to(t.hostVersions)}. Update @datadog/apps-frontend, rebuild this app, and upload the new bundle.`};case"HOST_MAJOR_TOO_OLD":return{code:"HOST_MAJOR_TOO_OLD",action:"contact-support",requestedVersion:t.wanted,availableVersions:t.hostVersions,message:`HOST_MAJOR_TOO_OLD: this app's claim requests v${t.wanted}, newer than the host's ${to(t.hostVersions)}. Rebuilding the app will not fix this; screenshot this message and contact support.`};case"CONTRACT_INCOMPATIBLE":return{code:"UNKNOWN",action:"contact-support",message:`CONTRACT_INCOMPATIBLE: the host omitted required field "${t.field}" despite advertising a compatible contract version. Screenshot this message and contact support.`};case"INVALID_RESULT":return{code:"UNKNOWN",action:"contact-support",message:`INVALID_RESULT: a host value failed this app's bundled parser (${Zo(t.issues)}). Screenshot this message and contact support.`};case"TIMED_OUT":return{code:"TIMED_OUT",action:"retry",message:`TIMED_OUT: the Datadog host did not complete the claim request within ${t.timeoutMs}ms. Reload the app to try again.`};case"DISCONNECTED":case"UNRECOGNIZED":return Yt(t);default:return t}}var Yo=0,Qo=Object.freeze({status:"pending"}),qo=Object.freeze({status:"unavailable"}),er=Object.freeze({code:"UNKNOWN",action:"contact-support",message:"EMBEDDING_CLOSED: the Datadog App connection closed while its provider was still mounted. Screenshot this message and contact support."}),qt=Object.freeze({code:"UNKNOWN",action:"contact-support",message:"CLAIM_REJECTED: the requested Datadog App claim failed unexpectedly. Screenshot this message and contact support."}),no=Object.freeze({code:"UNKNOWN",action:"contact-support",message:"CONNECTION_START_FAILED: the Datadog App connection could not be started. Screenshot this message and contact support."});function en(){return Qo}function oo(){return qo}function tr(t){let e="requestedVersion"in t?Object.freeze({...t,availableVersions:Object.freeze([...t.availableVersions])}):Object.freeze({...t});return Object.freeze({status:"failed",error:e})}var Re,pe,ve,vt=class{constructor(e,n){this.owner=e;this.resource=n;p(this,Re,new Set);p(this,pe);p(this,ve,!1);Fe(this,"subscribe",e=>{r(this,pe)!==void 0&&(globalThis.clearTimeout(r(this,pe)),l(this,pe,void 0));let n=()=>e();r(this,Re).add(n),r(this,ve)||(l(this,ve,!0),this.owner.activate(this.resource));let o=!0;return()=>{o&&(o=!1,r(this,Re).delete(n),r(this,Re).size===0&&r(this,pe)===void 0&&l(this,pe,globalThis.setTimeout(()=>{l(this,pe,void 0),r(this,Re).size===0&&r(this,ve)&&(l(this,ve,!1),this.owner.deactivate(this.resource))},Yo)))}})}owner;resource;notify(){ge(r(this,Re))}get isActive(){return r(this,ve)}};Re=new WeakMap,pe=new WeakMap,ve=new WeakMap;var Ae,$,Ie,G,ne,he,Je,E,ro,io,so,on,Ge,ye,ue,Ue,nn=class{constructor(e,n){p(this,E);p(this,Ae);p(this,$);p(this,Ie,en());p(this,G);p(this,ne);p(this,he);p(this,Je,[]);Fe(this,"getSnapshot",()=>r(this,Ie));Fe(this,"subscribe",e=>r(this,Ae).subscribe(e));l(this,$,n),l(this,Ae,new vt(e,this))}sync(e){if(!e){this.reset();return}switch(e.state){case"connected":if(r(this,G)===e.connection)return;a(this,E,ye).call(this),l(this,G,e.connection),a(this,E,Ue).call(this,en()),a(this,E,ro).call(this,e.connection);return;case"connecting":case"reconnecting":this.reset();return;case"not-embedded":l(this,G,void 0),a(this,E,ye).call(this),a(this,E,Ue).call(this,oo());return;case"rejected":l(this,G,void 0),a(this,E,ye).call(this),a(this,E,ue).call(this,Yt(e.error));return;case"closed":l(this,G,void 0),a(this,E,ye).call(this),a(this,E,ue).call(this,er);return;default:return e}}fail(e){l(this,G,void 0),a(this,E,ye).call(this),a(this,E,ue).call(this,e)}reset(){l(this,G,void 0),a(this,E,ye).call(this),a(this,E,Ue).call(this,en())}};Ae=new WeakMap,$=new WeakMap,Ie=new WeakMap,G=new WeakMap,ne=new WeakMap,he=new WeakMap,Je=new WeakMap,E=new WeakSet,ro=function(e){let n=new AbortController;l(this,ne,n);let o;try{o=e.claim(r(this,$),{signal:n.signal})}catch(i){y("a claim could not be requested",{side:"app",identifier:r(this,$).identifier,current:a(this,E,Ge).call(this,e,n),cause:S(i)}),a(this,E,Ge).call(this,e,n)&&(l(this,ne,void 0),a(this,E,ue).call(this,qt));return}o.then(i=>{if(!a(this,E,Ge).call(this,e,n)){i.ok&&i.value.release();return}if(l(this,ne,void 0),!i.ok){if(i.error.code==="PEER_LACKS_MODULE"){x("the Datadog host does not offer this module",{side:"app",identifier:r(this,$).identifier,version:r(this,$).version}),a(this,E,Ue).call(this,oo());return}if(i.error.code==="ABORTED"){a(this,E,ue).call(this,qt);return}a(this,E,ue).call(this,Qt(i.error));return}a(this,E,io).call(this,e,i.value)},i=>{y("a claim request rejected",{side:"app",identifier:r(this,$).identifier,current:a(this,E,Ge).call(this,e,n),cause:S(i)}),a(this,E,Ge).call(this,e,n)&&(l(this,ne,void 0),a(this,E,ue).call(this,qt))})},io=function(e,n){if(!r(this,Ae).isActive||r(this,G)!==e||r(this,he)){n.release();return}l(this,he,n),r(this,Je).push(n.onInvalidated(o=>a(this,E,so).call(this,n,o))),r(this,Je).push(n.onValuesChanged(()=>{r(this,he)===n&&a(this,E,on).call(this,n)})),a(this,E,on).call(this,n)},so=function(e,n){if(r(this,he)!==e)return;let o=Qt(n);a(this,E,ye).call(this),a(this,E,ue).call(this,o)},on=function(e){let n=Object.entries(r(this,$).fields),o=n.map(([s])=>s),i=Object.create(null);for(let[s,d]of n){let c=e.fields[s];i[s]=d.kind==="value"?c.get():c}if(r(this,Ie).status==="ready"){let s=r(this,Ie).fields;if(o.every(d=>Object.is(s[d],i[d])))return}a(this,E,Ue).call(this,Object.freeze({status:"ready",fields:Object.freeze(i)}))},Ge=function(e,n){return r(this,Ae).isActive&&r(this,G)===e&&r(this,ne)===n&&!n.signal.aborted},ye=function(){r(this,ne)?.abort(),l(this,ne,void 0);for(let n of r(this,Je).splice(0))n();let e=r(this,he);l(this,he,void 0),e?.release()},ue=function(e){y("a Datadog App claim failed",{side:"app",identifier:r(this,$).identifier,version:r(this,$).version,code:e.code,action:e.action,reason:e.message}),a(this,E,Ue).call(this,tr(e))},Ue=function(e){r(this,Ie)!==e&&(l(this,Ie,e),r(this,Ae).notify())};var tn=Object.freeze({state:"connecting"});function nr(t){switch(t.state){case"connecting":return{state:"connecting",error:t.error};case"connected":return{state:"connected",surfaceId:t.surfaceId};case"reconnecting":return{state:"reconnecting",lastError:t.lastError};case"rejected":return{state:"rejected",error:t.error};case"not-embedded":return{state:"not-embedded"};case"closed":return{state:"closed"};default:return t}}var Ke,Ze,Xe,Rt,rn=class{constructor(e){p(this,Xe);p(this,Ke);p(this,Ze,tn);Fe(this,"getSnapshot",()=>r(this,Ze));Fe(this,"subscribe",e=>r(this,Ke).subscribe(e));l(this,Ke,new vt(e,this))}sync(e){a(this,Xe,Rt).call(this,e?nr(e):tn)}fail(e){a(this,Xe,Rt).call(this,{state:"rejected",error:{code:"TRANSPORT_FAILED",cause:e}})}reset(){a(this,Xe,Rt).call(this,tn)}};Ke=new WeakMap,Ze=new WeakMap,Xe=new WeakSet,Rt=function(e){r(this,Ze)!==e&&(l(this,Ze,e),r(this,Ke).notify())};var lt,X,ut,fe,Ye,_e,Qe,Ve,L,ao,co,lo,uo,an,dn,cn,sn=class{constructor(e){this.connector=e;p(this,L);p(this,lt,new WeakMap);p(this,X,new Set);p(this,ut,{activate:e=>a(this,L,lo).call(this,e),deactivate:e=>a(this,L,uo).call(this,e)});p(this,fe);p(this,Ye);p(this,_e);p(this,Qe);p(this,Ve,0)}connector;getClaim(e){let n=e,o=r(this,lt).get(n);if(o)return o;let i=new nn(r(this,ut),e);return r(this,lt).set(n,i),i}getEmbeddingMetadata(){return r(this,Qe)||l(this,Qe,new rn(r(this,ut))),r(this,Qe)}start(){l(this,Ve,r(this,Ve)+1),r(this,Ve)===1&&a(this,L,ao).call(this);let e=!0;return()=>{e&&(e=!1,l(this,Ve,r(this,Ve)-1),r(this,Ve)===0&&a(this,L,co).call(this))}}};lt=new WeakMap,X=new WeakMap,ut=new WeakMap,fe=new WeakMap,Ye=new WeakMap,_e=new WeakMap,Qe=new WeakMap,Ve=new WeakMap,L=new WeakSet,ao=function(){l(this,_e,void 0);for(let n of r(this,X))n.reset();let e;try{e=this.connector.connect()}catch(n){a(this,L,cn).call(this,"connect",n);return}l(this,fe,e);try{l(this,Ye,e.subscribe(()=>a(this,L,an).call(this,e))),a(this,L,an).call(this,e)}catch(n){a(this,L,dn).call(this,e),a(this,L,cn).call(this,"subscribe",n);return}},co=function(){let e=r(this,fe);e&&a(this,L,dn).call(this,e),l(this,_e,void 0);for(let n of r(this,X))n.reset()},lo=function(e){if(r(this,X).add(e),r(this,_e)){e.fail(r(this,_e));return}e.sync(r(this,fe)?.getSnapshot())},uo=function(e){r(this,X).delete(e),e.reset()},an=function(e){if(r(this,fe)!==e)return;let n=e.getSnapshot();for(let o of r(this,X))o.sync(n)},dn=function(e){if(r(this,fe)!==e)return;l(this,fe,void 0);let n=r(this,Ye);l(this,Ye,void 0),n&&w("embedding connection handle unsubscribe",()=>n());for(let o of r(this,X))w("embedding claim resource reset",()=>o.reset());w("embedding connection handle close",()=>e.close())},cn=function(e,n){y("the embedding connection could not be started",{side:"app",step:e,affectedResources:r(this,X).size,cause:S(n)}),l(this,_e,no);for(let o of r(this,X))o.fail(no)};function po(t){return new sn(t)}var ho=po(eo),sr=In(ho),ar=Object.freeze([Rn()]);function dr(t){try{console.warn(t)}catch{}}function cr(t,e,n){let o=e??[],i=new Set(o.map(c=>c.id)),s=new Set(n??[]),d=t.filter(c=>!s.has(c.id)&&!i.has(c.id));if(s.size===0)return[...d,...o];for(let c of o)if(s.has(c.id))throw new Error(`DatadogAppProvider received module "${c.id}" in both modules and disabledModules.`);for(let c of s)t.some(f=>f.id===c)||o.some(f=>f.id===c)||dr(`[Datadog App provider] disabledModules names "${c}", but no module with that id is installed.`);return[...d,...o]}var lr=({children:t,modules:e,disabledModules:n})=>{let[o]=ir(()=>cr(ar,e,n));return rr(()=>{let i=new AbortController;return gn(o,ho,i.signal),()=>i.abort()},[o]),or(sr,null,t)};import{useSyncExternalStore as ur}from"react";var ln=new WeakMap;function fo(t){return t==="connecting"||t==="reconnecting"}function pr(t,e){let n=ln.get(e);if(!n){let o=vn(t),i;n=new Promise(h=>{i=h}),ln.set(e,n);let s,d=!1,c=()=>{d||fo(e.getSnapshot().state)||(d=!0,s?.(),ln.delete(e),An(t,o),i())};s=e.subscribe(c),d?s():c()}throw n}function hr(){throw new Error("useDatadogAppEmbedding does not support server rendering: the Datadog App embedding connection only exists in the browser.")}function fr(t){throw new Error(t.state==="rejected"?`The Datadog App embedding connection was rejected: ${t.error.code}.`:"The Datadog App embedding connection closed.")}function mr(t){let e=_n(),n=e.getEmbeddingMetadata(),o=ur(n.subscribe,n.getSnapshot,hr);return t?.suspense&&(fo(o.state)&&pr(e,n),(o.state==="rejected"||o.state==="closed")&&fr(o)),o}export{lr as DatadogAppProvider,mr as useDatadogAppEmbedding};
|
|
6
|
+
import {
|
|
7
|
+
a as gn,
|
|
8
|
+
b as Rn
|
|
9
|
+
} from "../../_chunks/chunk-SSORLL57.js";
|
|
10
|
+
import {
|
|
11
|
+
a as vn,
|
|
12
|
+
b as An,
|
|
13
|
+
c as In,
|
|
14
|
+
d as _n
|
|
15
|
+
} from "../../_chunks/chunk-VSZMABRM.js";
|
|
16
|
+
import "../../_chunks/chunk-ONCDAC2F.js";
|
|
17
|
+
import {
|
|
18
|
+
A as b,
|
|
19
|
+
B as k,
|
|
20
|
+
C as w,
|
|
21
|
+
D as ge,
|
|
22
|
+
a as Fe,
|
|
23
|
+
b as r,
|
|
24
|
+
c as p,
|
|
25
|
+
d as l,
|
|
26
|
+
e as a,
|
|
27
|
+
f as qe,
|
|
28
|
+
g as En,
|
|
29
|
+
h as Tn,
|
|
30
|
+
i as xe,
|
|
31
|
+
j as Cn,
|
|
32
|
+
k as On,
|
|
33
|
+
l as et,
|
|
34
|
+
m as It,
|
|
35
|
+
n as B,
|
|
36
|
+
o as tt,
|
|
37
|
+
p as bn,
|
|
38
|
+
q as yn,
|
|
39
|
+
r as _t,
|
|
40
|
+
s as Dt,
|
|
41
|
+
t as S,
|
|
42
|
+
u as J,
|
|
43
|
+
v as x,
|
|
44
|
+
w as y,
|
|
45
|
+
x as me,
|
|
46
|
+
y as P,
|
|
47
|
+
z as u
|
|
48
|
+
} from "../../_chunks/chunk-E6L6DSL7.js";
|
|
49
|
+
|
|
50
|
+
// src/embedding/react/provider.ts
|
|
51
|
+
import { createElement as or, useEffect as rr, useState as ir } from "react";
|
|
52
|
+
|
|
53
|
+
// src/embedding/handshake/origins.ts
|
|
54
|
+
var go = /^https:\/\/(?:[a-zA-Z0-9-]+\.)*(?:datadoghq\.(?:com|eu)|ddog-gov\.com)$/, Eo = /^https:\/\/(?:[a-zA-Z0-9-]+\.)*(?:datad0g\.com|datad0g\.eu|staging\.dog|prod\.dog)$/, To = /^https?:\/\/(?:localhost|127\.0\.0\.1)(?::\d+)?$/;
|
|
55
|
+
function Dn(t) {
|
|
56
|
+
return go.test(t) || Eo.test(t) || To.test(t);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/embedding/handshake/bootstrap.ts
|
|
60
|
+
var Mn = "dd-apps-frontend-bootstrap", Pn = 1;
|
|
61
|
+
function Oo(t, e, n) {
|
|
62
|
+
let { data: o } = n;
|
|
63
|
+
return n.source !== t || n.ports.length !== 0 || !b(o) || o.namespace !== Mn || o.version !== Pn || o.type !== "accepted" && o.type !== "rejected-origin" || o.attemptId !== e ? { status: "ignored" } : Dn(n.origin) ? o.type === "rejected-origin" ? typeof o.origin == "string" ? { status: "rejected-origin", origin: o.origin } : { status: "ignored" } : { status: "accepted" } : { status: "rejected-origin", origin: n.origin };
|
|
64
|
+
}
|
|
65
|
+
function wn(t, e, n, o = 1e4) {
|
|
66
|
+
if (n.aborted)
|
|
67
|
+
return Promise.resolve(u({ code: "ABORTED" }));
|
|
68
|
+
let i = t.parent;
|
|
69
|
+
if (i === t)
|
|
70
|
+
return Promise.resolve(
|
|
71
|
+
u({
|
|
72
|
+
code: "TRANSPORT_FAILED",
|
|
73
|
+
cause: new Error("The app is not running in an iframe.")
|
|
74
|
+
})
|
|
75
|
+
);
|
|
76
|
+
let s = me("bootstrap"), d = new MessageChannel();
|
|
77
|
+
return new Promise((c) => {
|
|
78
|
+
let h = !1, f = !1, m = !1, C, _ = (M) => {
|
|
79
|
+
h || (h = !0, t.removeEventListener("message", O), n.removeEventListener("abort", D), C !== void 0 && globalThis.clearTimeout(C), M.ok || (w(
|
|
80
|
+
"failed app bootstrap port",
|
|
81
|
+
() => d.port1.close()
|
|
82
|
+
), f || w(
|
|
83
|
+
"untransferred app bootstrap port",
|
|
84
|
+
() => d.port2.close()
|
|
85
|
+
)), c(M));
|
|
86
|
+
}, O = (M) => {
|
|
87
|
+
let T = Oo(
|
|
88
|
+
i,
|
|
89
|
+
s,
|
|
90
|
+
M
|
|
91
|
+
);
|
|
92
|
+
T.status === "accepted" ? _(P(d.port1)) : T.status === "rejected-origin" && _(
|
|
93
|
+
u({
|
|
94
|
+
code: "ORIGIN_REJECTED",
|
|
95
|
+
origin: T.origin
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
}, D = () => _(u({ code: "ABORTED" })), H = () => {
|
|
99
|
+
if (!(m || h)) {
|
|
100
|
+
m = !0, C = globalThis.setTimeout(
|
|
101
|
+
() => _(u({ code: "TIMED_OUT", timeoutMs: o })),
|
|
102
|
+
Math.max(0, o)
|
|
103
|
+
);
|
|
104
|
+
try {
|
|
105
|
+
i.postMessage(
|
|
106
|
+
{
|
|
107
|
+
namespace: Mn,
|
|
108
|
+
version: Pn,
|
|
109
|
+
type: "request",
|
|
110
|
+
attemptId: s,
|
|
111
|
+
documentId: e
|
|
112
|
+
},
|
|
113
|
+
"*",
|
|
114
|
+
[d.port2]
|
|
115
|
+
), f = !0;
|
|
116
|
+
} catch (M) {
|
|
117
|
+
_(u({ code: "TRANSPORT_FAILED", cause: M }));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
if (t.addEventListener("message", O), n.addEventListener("abort", D, { once: !0 }), n.aborted) {
|
|
122
|
+
D();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
H();
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
var Ln = me("document");
|
|
129
|
+
|
|
130
|
+
// src/embedding/handshake/compatibility.ts
|
|
131
|
+
var Nn = "dd-apps-frontend-compatibility", Sn = 1, bo = 64;
|
|
132
|
+
function yo(t, e, n, o) {
|
|
133
|
+
return n.aborted ? Promise.resolve({ ok: !1, error: { code: "ABORTED" } }) : new Promise((i) => {
|
|
134
|
+
let s = !1, d, c = (m) => {
|
|
135
|
+
s || (s = !0, t.removeEventListener("message", h), n.removeEventListener("abort", f), d !== void 0 && globalThis.clearTimeout(d), i(m));
|
|
136
|
+
}, h = (m) => c({ ok: !0, value: m }), f = () => c({ ok: !1, error: { code: "ABORTED" } });
|
|
137
|
+
t.addEventListener("message", h), n.addEventListener("abort", f, { once: !0 }), d = globalThis.setTimeout(
|
|
138
|
+
() => c({
|
|
139
|
+
ok: !1,
|
|
140
|
+
error: { code: "TIMED_OUT", timeoutMs: e }
|
|
141
|
+
}),
|
|
142
|
+
Math.max(0, e)
|
|
143
|
+
);
|
|
144
|
+
try {
|
|
145
|
+
t.start(), o?.();
|
|
146
|
+
} catch (m) {
|
|
147
|
+
c({
|
|
148
|
+
ok: !1,
|
|
149
|
+
error: { code: "TRANSPORT_FAILED", cause: m }
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function kn(t) {
|
|
155
|
+
if (!(!Array.isArray(t) || t.length === 0 || t.length > bo || !Array.from(t).every(
|
|
156
|
+
(e) => Number.isSafeInteger(e) && e > 0
|
|
157
|
+
) || new Set(t).size !== t.length))
|
|
158
|
+
return [...t].sort((e, n) => e - n);
|
|
159
|
+
}
|
|
160
|
+
function Ro(t, e) {
|
|
161
|
+
let n = t.filter(
|
|
162
|
+
(c) => e.includes(c)
|
|
163
|
+
);
|
|
164
|
+
if (n.length > 0)
|
|
165
|
+
return { ok: !0, value: Math.max(...n) };
|
|
166
|
+
let o = Math.min(...t), i = Math.max(...t), s = Math.min(...e), d = Math.max(...e);
|
|
167
|
+
return i < s ? {
|
|
168
|
+
ok: !1,
|
|
169
|
+
error: {
|
|
170
|
+
code: "APP_PROTOCOL_TOO_OLD",
|
|
171
|
+
appProtocols: t,
|
|
172
|
+
hostProtocols: e
|
|
173
|
+
}
|
|
174
|
+
} : d < o ? {
|
|
175
|
+
ok: !1,
|
|
176
|
+
error: {
|
|
177
|
+
code: "HOST_PROTOCOL_TOO_OLD",
|
|
178
|
+
appProtocols: t,
|
|
179
|
+
hostProtocols: e
|
|
180
|
+
}
|
|
181
|
+
} : {
|
|
182
|
+
ok: !1,
|
|
183
|
+
error: {
|
|
184
|
+
code: "PROTOCOL_INCOMPATIBLE",
|
|
185
|
+
appProtocols: t,
|
|
186
|
+
hostProtocols: e
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
async function Un(t, e, n, o) {
|
|
191
|
+
let i = kn(e);
|
|
192
|
+
if (!i)
|
|
193
|
+
return t.close(), {
|
|
194
|
+
ok: !1,
|
|
195
|
+
error: {
|
|
196
|
+
code: "TRANSPORT_FAILED",
|
|
197
|
+
cause: new Error("The app protocol registry is invalid.")
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
let s = await yo(
|
|
201
|
+
t,
|
|
202
|
+
n,
|
|
203
|
+
o,
|
|
204
|
+
() => {
|
|
205
|
+
t.postMessage({
|
|
206
|
+
namespace: Nn,
|
|
207
|
+
version: Sn,
|
|
208
|
+
type: "offer",
|
|
209
|
+
role: "app",
|
|
210
|
+
protocols: i
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
if (t.close(), !s.ok)
|
|
215
|
+
return s;
|
|
216
|
+
let { data: d, ports: c } = s.value;
|
|
217
|
+
if (!b(d) || d.namespace !== Nn || d.version !== Sn || d.type !== "answer" || d.role !== "host") {
|
|
218
|
+
for (let C of c)
|
|
219
|
+
C.close();
|
|
220
|
+
return {
|
|
221
|
+
ok: !1,
|
|
222
|
+
error: {
|
|
223
|
+
code: "TRANSPORT_FAILED",
|
|
224
|
+
cause: new Error(
|
|
225
|
+
"The host returned an invalid compatibility answer."
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
let h = kn(d.protocols);
|
|
231
|
+
if (!h) {
|
|
232
|
+
for (let C of c)
|
|
233
|
+
C.close();
|
|
234
|
+
return {
|
|
235
|
+
ok: !1,
|
|
236
|
+
error: {
|
|
237
|
+
code: "TRANSPORT_FAILED",
|
|
238
|
+
cause: new Error(
|
|
239
|
+
"The host returned an invalid supported-protocol list."
|
|
240
|
+
)
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
let f = Ro(i, h);
|
|
245
|
+
if (!f.ok) {
|
|
246
|
+
for (let C of c)
|
|
247
|
+
C.close();
|
|
248
|
+
return f;
|
|
249
|
+
}
|
|
250
|
+
let [m] = c;
|
|
251
|
+
if (c.length !== 1 || m === void 0) {
|
|
252
|
+
for (let C of c)
|
|
253
|
+
C.close();
|
|
254
|
+
return {
|
|
255
|
+
ok: !1,
|
|
256
|
+
error: {
|
|
257
|
+
code: "TRANSPORT_FAILED",
|
|
258
|
+
cause: new Error(
|
|
259
|
+
"A compatible host must transfer exactly one operational port."
|
|
260
|
+
)
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
ok: !0,
|
|
266
|
+
value: {
|
|
267
|
+
protocol: f.value,
|
|
268
|
+
operationalPort: m
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/embedding/protocol/establish.ts
|
|
274
|
+
import { connect as ko, PortMessenger as Uo, Reply as Vo } from "penpal";
|
|
275
|
+
|
|
276
|
+
// src/embedding/protocol/heartbeat.ts
|
|
277
|
+
var pt = "dd-apps-frontend-heartbeat", ht = 1, Vn = Object.freeze({
|
|
278
|
+
intervalMs: En,
|
|
279
|
+
timeoutMs: Tn
|
|
280
|
+
});
|
|
281
|
+
function rt(t) {
|
|
282
|
+
try {
|
|
283
|
+
t.postMessage({
|
|
284
|
+
namespace: pt,
|
|
285
|
+
version: ht,
|
|
286
|
+
type: "close"
|
|
287
|
+
});
|
|
288
|
+
} catch {
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function Fn(t, e) {
|
|
292
|
+
rt(e), globalThis.setTimeout(() => {
|
|
293
|
+
w("failed Penpal connection", () => t.destroy()), w("failed operational port", () => e.close());
|
|
294
|
+
}, xe);
|
|
295
|
+
}
|
|
296
|
+
var K, re, ie, nt, Q, ot, V, Mt, Pt, wt, ft, mt = class {
|
|
297
|
+
constructor(e, n, o, i) {
|
|
298
|
+
this.port = e;
|
|
299
|
+
this.onDead = n;
|
|
300
|
+
this.policy = o;
|
|
301
|
+
this.side = i;
|
|
302
|
+
p(this, V);
|
|
303
|
+
p(this, K);
|
|
304
|
+
p(this, re);
|
|
305
|
+
p(this, ie, 0);
|
|
306
|
+
p(this, nt, !1);
|
|
307
|
+
p(this, Q, !1);
|
|
308
|
+
p(this, ot, (e) => {
|
|
309
|
+
let n = e.data;
|
|
310
|
+
if (!(!b(n) || n.namespace !== pt || n.version !== ht)) {
|
|
311
|
+
if (n.type === "close") {
|
|
312
|
+
a(this, V, ft).call(this, !1);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
if (k(n.nonce)) {
|
|
316
|
+
if (n.type === "ping") {
|
|
317
|
+
try {
|
|
318
|
+
this.port.postMessage({
|
|
319
|
+
namespace: pt,
|
|
320
|
+
version: ht,
|
|
321
|
+
type: "pong",
|
|
322
|
+
nonce: n.nonce
|
|
323
|
+
});
|
|
324
|
+
} catch (o) {
|
|
325
|
+
y("could not answer a heartbeat probe", {
|
|
326
|
+
side: this.side,
|
|
327
|
+
cause: S(o)
|
|
328
|
+
}), a(this, V, ft).call(this, !0);
|
|
329
|
+
}
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
n.type !== "pong" || n.nonce !== r(this, re) || (l(this, re, void 0), l(this, ie, 0), r(this, K) !== void 0 && (globalThis.clearTimeout(r(this, K)), l(this, K, void 0)), a(this, V, Mt).call(this, this.policy.intervalMs));
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
this.port.addEventListener("message", r(this, ot));
|
|
337
|
+
}
|
|
338
|
+
port;
|
|
339
|
+
onDead;
|
|
340
|
+
policy;
|
|
341
|
+
side;
|
|
342
|
+
start() {
|
|
343
|
+
r(this, nt) || r(this, Q) || (l(this, nt, !0), a(this, V, Mt).call(this, this.policy.intervalMs));
|
|
344
|
+
}
|
|
345
|
+
stop() {
|
|
346
|
+
r(this, Q) || (l(this, Q, !0), l(this, re, void 0), r(this, K) !== void 0 && (globalThis.clearTimeout(r(this, K)), l(this, K, void 0)), this.port.removeEventListener("message", r(this, ot)));
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
K = new WeakMap(), re = new WeakMap(), ie = new WeakMap(), nt = new WeakMap(), Q = new WeakMap(), ot = new WeakMap(), V = new WeakSet(), Mt = function(e) {
|
|
350
|
+
r(this, Q) || l(this, K, globalThis.setTimeout(
|
|
351
|
+
() => a(this, V, Pt).call(this),
|
|
352
|
+
Math.max(0, e)
|
|
353
|
+
));
|
|
354
|
+
}, Pt = function() {
|
|
355
|
+
if (r(this, Q))
|
|
356
|
+
return;
|
|
357
|
+
let e = me("heartbeat");
|
|
358
|
+
l(this, re, e);
|
|
359
|
+
try {
|
|
360
|
+
this.port.postMessage({
|
|
361
|
+
namespace: pt,
|
|
362
|
+
version: ht,
|
|
363
|
+
type: "ping",
|
|
364
|
+
nonce: e
|
|
365
|
+
});
|
|
366
|
+
} catch (n) {
|
|
367
|
+
x("could not send a heartbeat probe", {
|
|
368
|
+
side: this.side,
|
|
369
|
+
misses: r(this, ie),
|
|
370
|
+
cause: S(n)
|
|
371
|
+
}), a(this, V, wt).call(this, e);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
l(this, K, globalThis.setTimeout(
|
|
375
|
+
() => a(this, V, wt).call(this, e),
|
|
376
|
+
Math.max(0, this.policy.timeoutMs)
|
|
377
|
+
));
|
|
378
|
+
}, wt = function(e) {
|
|
379
|
+
if (!(r(this, Q) || r(this, re) !== e)) {
|
|
380
|
+
if (l(this, re, void 0), l(this, ie, r(this, ie) + 1), r(this, ie) >= 2) {
|
|
381
|
+
y("the peer stopped answering heartbeats", {
|
|
382
|
+
side: this.side,
|
|
383
|
+
misses: r(this, ie),
|
|
384
|
+
probeTimeoutMs: this.policy.timeoutMs,
|
|
385
|
+
intervalMs: this.policy.intervalMs
|
|
386
|
+
}), a(this, V, ft).call(this, !0);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
x("a heartbeat probe went unanswered", {
|
|
390
|
+
side: this.side,
|
|
391
|
+
misses: r(this, ie),
|
|
392
|
+
probeTimeoutMs: this.policy.timeoutMs
|
|
393
|
+
}), a(this, V, Pt).call(this);
|
|
394
|
+
}
|
|
395
|
+
}, ft = function(e) {
|
|
396
|
+
r(this, Q) || (this.stop(), this.onDead(e));
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
// src/embedding/protocol/validation.ts
|
|
400
|
+
import { Reply as vo } from "penpal";
|
|
401
|
+
function Ao(t) {
|
|
402
|
+
return (typeof t == "object" && t !== null || typeof t == "function") && typeof t.then == "function";
|
|
403
|
+
}
|
|
404
|
+
function De(t) {
|
|
405
|
+
return typeof t == "number" && Number.isSafeInteger(t) && t >= 1;
|
|
406
|
+
}
|
|
407
|
+
function Nt(t) {
|
|
408
|
+
return Array.isArray(t) && t.every(De);
|
|
409
|
+
}
|
|
410
|
+
function Me(t) {
|
|
411
|
+
return Array.isArray(t) && t.every(
|
|
412
|
+
(e) => typeof e == "number" && Number.isSafeInteger(e) && e > 0
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
function Io(t) {
|
|
416
|
+
return Array.isArray(t) && t.every(
|
|
417
|
+
(e) => typeof e == "string" || typeof e == "number" && Number.isSafeInteger(e) && e >= 0
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
function St(t) {
|
|
421
|
+
return Array.isArray(t) && t.every(
|
|
422
|
+
(e) => b(e) && typeof e.message == "string" && Io(e.path)
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
function Pe(t, e) {
|
|
426
|
+
try {
|
|
427
|
+
let n = t["~standard"].validate(e);
|
|
428
|
+
return Ao(n) ? (Promise.resolve(n).catch(() => {
|
|
429
|
+
}), u([
|
|
430
|
+
{
|
|
431
|
+
message: "Embedding value schemas must be synchronous.",
|
|
432
|
+
path: []
|
|
433
|
+
}
|
|
434
|
+
])) : n.issues ? u(
|
|
435
|
+
n.issues.map((o) => ({
|
|
436
|
+
message: o.message,
|
|
437
|
+
path: _o(o.path)
|
|
438
|
+
}))
|
|
439
|
+
) : P(n.value);
|
|
440
|
+
} catch (n) {
|
|
441
|
+
return u([
|
|
442
|
+
{
|
|
443
|
+
message: n instanceof Error ? n.message : "The value parser rejected this value.",
|
|
444
|
+
path: []
|
|
445
|
+
}
|
|
446
|
+
]);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function _o(t) {
|
|
450
|
+
return t ? t.map((e) => {
|
|
451
|
+
let n = typeof e == "object" && e !== null && "key" in e ? e.key : e;
|
|
452
|
+
return typeof n == "string" || typeof n == "number" && Number.isSafeInteger(n) && n >= 0 ? n : String(n);
|
|
453
|
+
}) : [];
|
|
454
|
+
}
|
|
455
|
+
function it(t, e = [], n = /* @__PURE__ */ new Set()) {
|
|
456
|
+
try {
|
|
457
|
+
globalThis.structuredClone(t);
|
|
458
|
+
return;
|
|
459
|
+
} catch {
|
|
460
|
+
if (typeof t != "object" && typeof t != "function" || t === null || n.has(t))
|
|
461
|
+
return e;
|
|
462
|
+
n.add(t);
|
|
463
|
+
let o;
|
|
464
|
+
try {
|
|
465
|
+
o = Object.entries(t);
|
|
466
|
+
} catch {
|
|
467
|
+
return e;
|
|
468
|
+
}
|
|
469
|
+
for (let [i, s] of o) {
|
|
470
|
+
let d = it(
|
|
471
|
+
s,
|
|
472
|
+
[...e, Array.isArray(t) ? Number(i) : i],
|
|
473
|
+
n
|
|
474
|
+
);
|
|
475
|
+
if (d)
|
|
476
|
+
return d;
|
|
477
|
+
}
|
|
478
|
+
return e;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
function He(t, e) {
|
|
482
|
+
return e.map((n) => ({
|
|
483
|
+
message: n.message,
|
|
484
|
+
path: [t, ...n.path]
|
|
485
|
+
}));
|
|
486
|
+
}
|
|
487
|
+
function gt(t) {
|
|
488
|
+
return Object.entries(t.fields).filter(([, e]) => e.kind === "value").map(([e]) => e);
|
|
489
|
+
}
|
|
490
|
+
function xn(t, e, n) {
|
|
491
|
+
let o = new Set(t);
|
|
492
|
+
if (n) {
|
|
493
|
+
let s = [...o].find(
|
|
494
|
+
(d) => !Object.prototype.hasOwnProperty.call(e, d)
|
|
495
|
+
);
|
|
496
|
+
if (s !== void 0)
|
|
497
|
+
return { field: s, kind: "missing" };
|
|
498
|
+
}
|
|
499
|
+
let i = Object.keys(e).find(
|
|
500
|
+
(s) => !o.has(s)
|
|
501
|
+
);
|
|
502
|
+
return i === void 0 ? void 0 : { field: i, kind: "unknown" };
|
|
503
|
+
}
|
|
504
|
+
function Hn(t) {
|
|
505
|
+
return {
|
|
506
|
+
code: "INVALID_RESULT",
|
|
507
|
+
issues: [
|
|
508
|
+
{
|
|
509
|
+
message: t.kind === "missing" ? "The host value snapshot omitted a claimed field." : "The host value snapshot included an unclaimed field.",
|
|
510
|
+
path: [t.field]
|
|
511
|
+
}
|
|
512
|
+
]
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
function Et(t, e) {
|
|
516
|
+
let n = xn(t, e, !0);
|
|
517
|
+
return n && Hn(n);
|
|
518
|
+
}
|
|
519
|
+
function kt(t, e) {
|
|
520
|
+
let n = xn(t, e, !1);
|
|
521
|
+
return n && Hn(n);
|
|
522
|
+
}
|
|
523
|
+
function Ut(t, e, n) {
|
|
524
|
+
let o;
|
|
525
|
+
try {
|
|
526
|
+
o = n.get();
|
|
527
|
+
} catch (s) {
|
|
528
|
+
return y("a host value provider threw while being read", {
|
|
529
|
+
side: "host",
|
|
530
|
+
field: t,
|
|
531
|
+
cause: S(s)
|
|
532
|
+
}), u([
|
|
533
|
+
{
|
|
534
|
+
message: "The host value provider threw while being read.",
|
|
535
|
+
path: [t]
|
|
536
|
+
}
|
|
537
|
+
]);
|
|
538
|
+
}
|
|
539
|
+
let i = Pe(e, o);
|
|
540
|
+
if (!i.ok)
|
|
541
|
+
return u(He(t, i.error));
|
|
542
|
+
try {
|
|
543
|
+
return P(globalThis.structuredClone(i.value));
|
|
544
|
+
} catch {
|
|
545
|
+
let s = it(i.value) ?? [];
|
|
546
|
+
return u([
|
|
547
|
+
{
|
|
548
|
+
message: "The host value is not structured-clone-safe.",
|
|
549
|
+
path: [t, ...s]
|
|
550
|
+
}
|
|
551
|
+
]);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
function Tt(t, e, n) {
|
|
555
|
+
return y("a host value could not be provided", {
|
|
556
|
+
side: "host",
|
|
557
|
+
target: `${t}.${e}`,
|
|
558
|
+
details: S(n)
|
|
559
|
+
}), [
|
|
560
|
+
{
|
|
561
|
+
message: "The host could not provide a value that satisfies this field schema.",
|
|
562
|
+
path: [e]
|
|
563
|
+
}
|
|
564
|
+
];
|
|
565
|
+
}
|
|
566
|
+
function Vt(t, e, n) {
|
|
567
|
+
if (!b(n))
|
|
568
|
+
return u([
|
|
569
|
+
{
|
|
570
|
+
message: "Expected a named inputs object.",
|
|
571
|
+
path: [t, "inputs"]
|
|
572
|
+
}
|
|
573
|
+
]);
|
|
574
|
+
let o = Object.keys(n).find(
|
|
575
|
+
(s) => !Object.hasOwn(e.inputs, s)
|
|
576
|
+
);
|
|
577
|
+
if (o !== void 0)
|
|
578
|
+
return u([
|
|
579
|
+
{
|
|
580
|
+
message: `Unknown function input "${o}".`,
|
|
581
|
+
path: [t, "inputs", o]
|
|
582
|
+
}
|
|
583
|
+
]);
|
|
584
|
+
let i = /* @__PURE__ */ Object.create(null);
|
|
585
|
+
for (let [s, d] of Object.entries(e.inputs)) {
|
|
586
|
+
let c = Pe(
|
|
587
|
+
d,
|
|
588
|
+
Object.hasOwn(n, s) ? n[s] : void 0
|
|
589
|
+
);
|
|
590
|
+
if (!c.ok)
|
|
591
|
+
return u(
|
|
592
|
+
c.error.map((h) => ({
|
|
593
|
+
message: h.message,
|
|
594
|
+
path: [t, "inputs", s, ...h.path]
|
|
595
|
+
}))
|
|
596
|
+
);
|
|
597
|
+
i[s] = c.value;
|
|
598
|
+
}
|
|
599
|
+
try {
|
|
600
|
+
return P(globalThis.structuredClone(i));
|
|
601
|
+
} catch {
|
|
602
|
+
let s = it(i) ?? [];
|
|
603
|
+
return u([
|
|
604
|
+
{
|
|
605
|
+
message: "The function inputs are not structured-clone-safe.",
|
|
606
|
+
path: [t, "inputs", ...s]
|
|
607
|
+
}
|
|
608
|
+
]);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
function jn(t) {
|
|
612
|
+
if (typeof t != "object" || t === null || typeof globalThis.MessagePort != "function")
|
|
613
|
+
return !1;
|
|
614
|
+
if (t instanceof globalThis.MessagePort)
|
|
615
|
+
return !0;
|
|
616
|
+
let e = globalThis.MessagePort.prototype;
|
|
617
|
+
for (; e; ) {
|
|
618
|
+
let n = Object.getOwnPropertyDescriptor(
|
|
619
|
+
e,
|
|
620
|
+
"onmessage"
|
|
621
|
+
)?.get;
|
|
622
|
+
if (n)
|
|
623
|
+
try {
|
|
624
|
+
return n.call(t), !0;
|
|
625
|
+
} catch {
|
|
626
|
+
return !1;
|
|
627
|
+
}
|
|
628
|
+
e = Object.getPrototypeOf(e);
|
|
629
|
+
}
|
|
630
|
+
return !1;
|
|
631
|
+
}
|
|
632
|
+
var Bn = /* @__PURE__ */ Object.freeze({
|
|
633
|
+
"~standard": {
|
|
634
|
+
version: 1,
|
|
635
|
+
vendor: "@datadog/apps-frontend",
|
|
636
|
+
validate(t) {
|
|
637
|
+
return jn(t) ? { value: t } : { issues: [{ message: "Expected a MessagePort." }] };
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
function st(t) {
|
|
642
|
+
jn(t) && w("discarded function result MessagePort", () => t.close());
|
|
643
|
+
}
|
|
644
|
+
function Lt(t, e = []) {
|
|
645
|
+
return u([
|
|
646
|
+
{
|
|
647
|
+
message: "The function result is not structured-clone-safe.",
|
|
648
|
+
path: [t, ...e]
|
|
649
|
+
}
|
|
650
|
+
]);
|
|
651
|
+
}
|
|
652
|
+
function zn(t, e, n) {
|
|
653
|
+
let o = Pe(e.result, n);
|
|
654
|
+
if (!o.ok)
|
|
655
|
+
return u(He(t, o.error));
|
|
656
|
+
if (e.result === Bn) {
|
|
657
|
+
let i = o.value;
|
|
658
|
+
try {
|
|
659
|
+
let s = globalThis.structuredClone(i, {
|
|
660
|
+
transfer: [i]
|
|
661
|
+
});
|
|
662
|
+
return P(
|
|
663
|
+
new vo(P(s), { transferables: [s] })
|
|
664
|
+
);
|
|
665
|
+
} catch {
|
|
666
|
+
return Lt(t);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
try {
|
|
670
|
+
return P(P(globalThis.structuredClone(o.value)));
|
|
671
|
+
} catch {
|
|
672
|
+
let i = it(o.value) ?? [];
|
|
673
|
+
return Lt(t, i);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
function Wn(t, e, n) {
|
|
677
|
+
let o = Pe(e.result, n);
|
|
678
|
+
if (!o.ok)
|
|
679
|
+
return u(He(t, o.error));
|
|
680
|
+
if (e.result === Bn)
|
|
681
|
+
return P(o.value);
|
|
682
|
+
try {
|
|
683
|
+
return P(globalThis.structuredClone(o.value));
|
|
684
|
+
} catch {
|
|
685
|
+
let i = it(o.value) ?? [];
|
|
686
|
+
return Lt(t, i);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// src/embedding/protocol/wire-errors.ts
|
|
691
|
+
import { ErrorCode as Do, PenpalError as Mo } from "penpal";
|
|
692
|
+
function Po(t) {
|
|
693
|
+
let e = t.wanted, n = t.hostVersions;
|
|
694
|
+
return De(e) && Nt(n) && !n.includes(e) && n.some((o) => o > e);
|
|
695
|
+
}
|
|
696
|
+
function wo(t) {
|
|
697
|
+
let e = t.wanted, n = t.hostVersions;
|
|
698
|
+
return De(e) && Nt(n) && !n.includes(e) && n.every((o) => o < e);
|
|
699
|
+
}
|
|
700
|
+
var $n = {
|
|
701
|
+
ORIGIN_REJECTED: (t) => typeof t.origin == "string",
|
|
702
|
+
APP_PROTOCOL_TOO_OLD: (t) => Me(t.appProtocols) && Me(t.hostProtocols),
|
|
703
|
+
HOST_PROTOCOL_TOO_OLD: (t) => Me(t.appProtocols) && Me(t.hostProtocols),
|
|
704
|
+
PROTOCOL_INCOMPATIBLE: (t) => Me(t.appProtocols) && Me(t.hostProtocols),
|
|
705
|
+
PEER_LACKS_MODULE: (t) => typeof t.identifier == "string",
|
|
706
|
+
APP_MAJOR_TOO_OLD: Po,
|
|
707
|
+
HOST_MAJOR_TOO_OLD: wo,
|
|
708
|
+
CONTRACT_INCOMPATIBLE: (t) => typeof t.field == "string",
|
|
709
|
+
INVALID_ARGUMENT: (t) => St(t.issues),
|
|
710
|
+
FUNCTION_FAILED: (t) => typeof t.field == "string",
|
|
711
|
+
INVALID_RESULT: (t) => St(t.issues),
|
|
712
|
+
TIMED_OUT: (t) => typeof t.timeoutMs == "number" && Number.isFinite(t.timeoutMs) && t.timeoutMs >= 0,
|
|
713
|
+
TRANSPORT_FAILED: () => !0,
|
|
714
|
+
ABORTED: () => !0,
|
|
715
|
+
DISCONNECTED: () => !0,
|
|
716
|
+
UNRECOGNIZED: (t) => typeof t.rawCode == "string" && t.rawCode.length > 0
|
|
717
|
+
}, Lo = {
|
|
718
|
+
ORIGIN_REJECTED: ["origin"],
|
|
719
|
+
APP_PROTOCOL_TOO_OLD: ["appProtocols", "hostProtocols"],
|
|
720
|
+
HOST_PROTOCOL_TOO_OLD: ["appProtocols", "hostProtocols"],
|
|
721
|
+
PROTOCOL_INCOMPATIBLE: ["appProtocols", "hostProtocols"],
|
|
722
|
+
PEER_LACKS_MODULE: ["identifier"],
|
|
723
|
+
APP_MAJOR_TOO_OLD: ["wanted", "hostVersions"],
|
|
724
|
+
HOST_MAJOR_TOO_OLD: ["wanted", "hostVersions"],
|
|
725
|
+
CONTRACT_INCOMPATIBLE: ["field"],
|
|
726
|
+
INVALID_ARGUMENT: ["issues"],
|
|
727
|
+
FUNCTION_FAILED: ["field"],
|
|
728
|
+
INVALID_RESULT: ["issues"],
|
|
729
|
+
TIMED_OUT: ["timeoutMs"],
|
|
730
|
+
// TRANSPORT_FAILED is code-only on the wire: a peer-supplied cause could
|
|
731
|
+
// otherwise carry an Error message/stack or arbitrary structured-cloneable
|
|
732
|
+
// data across the embedding boundary. No current call site's `allowed`
|
|
733
|
+
// list includes TRANSPORT_FAILED, but keep this array empty so that
|
|
734
|
+
// can't change silently in the future.
|
|
735
|
+
TRANSPORT_FAILED: [],
|
|
736
|
+
ABORTED: [],
|
|
737
|
+
DISCONNECTED: [],
|
|
738
|
+
UNRECOGNIZED: ["rawCode", "raw"]
|
|
739
|
+
};
|
|
740
|
+
function Ct(t, e) {
|
|
741
|
+
if (b(t) && typeof t.code == "string") {
|
|
742
|
+
let n = t.code;
|
|
743
|
+
if (e.includes(n) && Object.prototype.hasOwnProperty.call($n, n)) {
|
|
744
|
+
let o = $n[n];
|
|
745
|
+
if (o(t)) {
|
|
746
|
+
if (n === "UNRECOGNIZED")
|
|
747
|
+
return {
|
|
748
|
+
code: n,
|
|
749
|
+
rawCode: t.rawCode,
|
|
750
|
+
raw: void 0
|
|
751
|
+
};
|
|
752
|
+
let i = { code: n };
|
|
753
|
+
for (let s of Lo[n])
|
|
754
|
+
i[s] = t[s];
|
|
755
|
+
return i;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return {
|
|
760
|
+
code: "UNRECOGNIZED",
|
|
761
|
+
rawCode: b(t) && typeof t.code == "string" ? t.code : "MALFORMED_ERROR",
|
|
762
|
+
raw: void 0
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
function Ee(t, e, n) {
|
|
766
|
+
let o = `${t.identifier}.${e}`, i = n.code === "UNRECOGNIZED" ? "UNKNOWN" : n.code, s;
|
|
767
|
+
switch (n.code) {
|
|
768
|
+
case "INVALID_ARGUMENT":
|
|
769
|
+
s = `The inputs passed to "${o}" are invalid: ${n.issues[0]?.message ?? "the schema rejected them"}.`;
|
|
770
|
+
break;
|
|
771
|
+
case "INVALID_RESULT":
|
|
772
|
+
s = `Datadog returned an invalid result from "${o}": ${n.issues[0]?.message ?? "the schema rejected it"}. The app and host may be using incompatible schema implementations.`;
|
|
773
|
+
break;
|
|
774
|
+
case "FUNCTION_FAILED":
|
|
775
|
+
s = `Datadog could not complete "${o}". Screenshot this message and contact support if the problem continues.`;
|
|
776
|
+
break;
|
|
777
|
+
case "TIMED_OUT":
|
|
778
|
+
s = `"${o}" did not finish within ${n.timeoutMs} ms. It may still complete in Datadog; do not automatically retry an action that is not idempotent.`;
|
|
779
|
+
break;
|
|
780
|
+
case "CONTRACT_INCOMPATIBLE":
|
|
781
|
+
s = `The Datadog host contract for "${o}" does not match the schema compiled into this app. Update the app or contact support.`;
|
|
782
|
+
break;
|
|
783
|
+
case "ABORTED":
|
|
784
|
+
s = `The inputs used by "${o}" were released before it completed. Its outcome is unknown; wait for the inputs to become ready before calling it again.`;
|
|
785
|
+
break;
|
|
786
|
+
case "DISCONNECTED":
|
|
787
|
+
s = `The Datadog connection closed before "${o}" completed. Its outcome is unknown; reconnect before trying again.`;
|
|
788
|
+
break;
|
|
789
|
+
case "UNRECOGNIZED":
|
|
790
|
+
s = `Datadog returned an unrecognized failure for "${o}" (${n.rawCode}). Screenshot this message and contact support.`;
|
|
791
|
+
break;
|
|
792
|
+
default:
|
|
793
|
+
s = n;
|
|
794
|
+
}
|
|
795
|
+
let d = new Error(
|
|
796
|
+
`DATADOG_APP_INPUT_FUNCTION_${i}: ${s}`,
|
|
797
|
+
{ cause: n }
|
|
798
|
+
);
|
|
799
|
+
return d.name = "DatadogAppInputFunctionError", y("a Datadog host function call failed", {
|
|
800
|
+
side: "app",
|
|
801
|
+
target: o,
|
|
802
|
+
error: J(n)
|
|
803
|
+
}), Object.assign(d, { code: i });
|
|
804
|
+
}
|
|
805
|
+
function Gn(t, e) {
|
|
806
|
+
return b(t) && t.code === "ABORTED" ? { code: "ABORTED" } : b(t) && t.code === "TIMED_OUT" ? { code: "TIMED_OUT", timeoutMs: e } : b(t) && t.code === "DISCONNECTED" ? { code: "DISCONNECTED" } : t instanceof Mo && t.code === Do.ConnectionTimeout ? { code: "TIMED_OUT", timeoutMs: e } : { code: "TRANSPORT_FAILED", cause: t };
|
|
807
|
+
}
|
|
808
|
+
function Jn(t) {
|
|
809
|
+
if (!b(t))
|
|
810
|
+
return {
|
|
811
|
+
code: "INVALID_RESULT",
|
|
812
|
+
issues: [
|
|
813
|
+
{
|
|
814
|
+
message: "Malformed __ddClaim envelope: expected an object.",
|
|
815
|
+
path: []
|
|
816
|
+
}
|
|
817
|
+
]
|
|
818
|
+
};
|
|
819
|
+
if (!k(t.claimId, B))
|
|
820
|
+
return {
|
|
821
|
+
code: "INVALID_RESULT",
|
|
822
|
+
issues: [
|
|
823
|
+
{
|
|
824
|
+
message: `"claimId" must contain between 1 and ${B} characters.`,
|
|
825
|
+
path: ["claimId"]
|
|
826
|
+
}
|
|
827
|
+
]
|
|
828
|
+
};
|
|
829
|
+
if (!k(t.identifier))
|
|
830
|
+
return {
|
|
831
|
+
code: "INVALID_RESULT",
|
|
832
|
+
issues: [
|
|
833
|
+
{
|
|
834
|
+
message: '"identifier" must be a non-empty string.',
|
|
835
|
+
path: ["identifier"]
|
|
836
|
+
}
|
|
837
|
+
]
|
|
838
|
+
};
|
|
839
|
+
if (!De(t.version))
|
|
840
|
+
return {
|
|
841
|
+
code: "INVALID_RESULT",
|
|
842
|
+
issues: [
|
|
843
|
+
{
|
|
844
|
+
message: '"version" must be a positive integer.',
|
|
845
|
+
path: ["version"]
|
|
846
|
+
}
|
|
847
|
+
]
|
|
848
|
+
};
|
|
849
|
+
if (!Array.isArray(t.fields) || t.fields.length === 0 || t.fields.length > _t)
|
|
850
|
+
return {
|
|
851
|
+
code: "INVALID_RESULT",
|
|
852
|
+
issues: [
|
|
853
|
+
{
|
|
854
|
+
message: `"fields" must contain between 1 and ${_t} entries.`,
|
|
855
|
+
path: ["fields"]
|
|
856
|
+
}
|
|
857
|
+
]
|
|
858
|
+
};
|
|
859
|
+
if (!t.fields.every(
|
|
860
|
+
(e) => typeof e == "string" && e.length > 0 && e.length <= Dt
|
|
861
|
+
) || new Set(t.fields).size !== t.fields.length)
|
|
862
|
+
return {
|
|
863
|
+
code: "INVALID_RESULT",
|
|
864
|
+
issues: [
|
|
865
|
+
{
|
|
866
|
+
message: `"fields" must contain unique non-empty strings of at most ${Dt} characters.`,
|
|
867
|
+
path: ["fields"]
|
|
868
|
+
}
|
|
869
|
+
]
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
function Kn(t) {
|
|
873
|
+
if (!b(t))
|
|
874
|
+
return {
|
|
875
|
+
code: "INVALID_ARGUMENT",
|
|
876
|
+
issues: [
|
|
877
|
+
{
|
|
878
|
+
message: "Malformed __ddCall envelope: expected an object.",
|
|
879
|
+
path: []
|
|
880
|
+
}
|
|
881
|
+
]
|
|
882
|
+
};
|
|
883
|
+
if (!k(t.claimId, B))
|
|
884
|
+
return {
|
|
885
|
+
code: "INVALID_ARGUMENT",
|
|
886
|
+
issues: [
|
|
887
|
+
{
|
|
888
|
+
message: `"claimId" must contain between 1 and ${B} characters.`,
|
|
889
|
+
path: ["claimId"]
|
|
890
|
+
}
|
|
891
|
+
]
|
|
892
|
+
};
|
|
893
|
+
if (!k(t.callId, tt))
|
|
894
|
+
return {
|
|
895
|
+
code: "INVALID_ARGUMENT",
|
|
896
|
+
issues: [
|
|
897
|
+
{
|
|
898
|
+
message: `"callId" must contain between 1 and ${tt} characters.`,
|
|
899
|
+
path: ["callId"]
|
|
900
|
+
}
|
|
901
|
+
]
|
|
902
|
+
};
|
|
903
|
+
if (!k(t.field))
|
|
904
|
+
return {
|
|
905
|
+
code: "INVALID_ARGUMENT",
|
|
906
|
+
issues: [
|
|
907
|
+
{
|
|
908
|
+
message: '"field" must be a non-empty string.',
|
|
909
|
+
path: ["field"]
|
|
910
|
+
}
|
|
911
|
+
]
|
|
912
|
+
};
|
|
913
|
+
if (!b(t.inputs))
|
|
914
|
+
return {
|
|
915
|
+
code: "INVALID_ARGUMENT",
|
|
916
|
+
issues: [
|
|
917
|
+
{
|
|
918
|
+
message: '"inputs" must be an object.',
|
|
919
|
+
path: ["inputs"]
|
|
920
|
+
}
|
|
921
|
+
]
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
function Ft(t, e) {
|
|
925
|
+
let n = e.map(({ version: s }) => s).sort((s, d) => s - d), o = n[n.length - 1];
|
|
926
|
+
if (o === void 0)
|
|
927
|
+
return u({ code: "HOST_MAJOR_TOO_OLD", wanted: t, hostVersions: n });
|
|
928
|
+
let i = e.find(({ version: s }) => s === t);
|
|
929
|
+
return i ? P(i) : u(
|
|
930
|
+
t < o ? { code: "APP_MAJOR_TOO_OLD", wanted: t, hostVersions: n } : { code: "HOST_MAJOR_TOO_OLD", wanted: t, hostVersions: n }
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
function Zn(t, e) {
|
|
934
|
+
let n = e.filter(
|
|
935
|
+
({ identifier: i }) => i === t.identifier
|
|
936
|
+
);
|
|
937
|
+
if (n.length === 0)
|
|
938
|
+
return {
|
|
939
|
+
code: "PEER_LACKS_MODULE",
|
|
940
|
+
identifier: t.identifier
|
|
941
|
+
};
|
|
942
|
+
let o = Ft(t.version, n);
|
|
943
|
+
return o.ok ? void 0 : o.error;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// src/embedding/protocol/endpoint.ts
|
|
947
|
+
var Le, Ht = class {
|
|
948
|
+
constructor(e) {
|
|
949
|
+
this.value = e;
|
|
950
|
+
p(this, Le, /* @__PURE__ */ new Set());
|
|
951
|
+
}
|
|
952
|
+
value;
|
|
953
|
+
get() {
|
|
954
|
+
return this.value;
|
|
955
|
+
}
|
|
956
|
+
subscribe(e) {
|
|
957
|
+
return r(this, Le).add(e), () => {
|
|
958
|
+
r(this, Le).delete(e);
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
set(e) {
|
|
962
|
+
return Object.is(this.value, e) ? !1 : (this.value = e, !0);
|
|
963
|
+
}
|
|
964
|
+
notify() {
|
|
965
|
+
ge(r(this, Le));
|
|
966
|
+
}
|
|
967
|
+
// A dead claim retains its last value only as a teardown safety net. The
|
|
968
|
+
// owning resource must leave ready state when the claim is invalidated.
|
|
969
|
+
freeze() {
|
|
970
|
+
r(this, Le).clear();
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
Le = new WeakMap();
|
|
974
|
+
var xt = 0;
|
|
975
|
+
function Xn(t) {
|
|
976
|
+
let e = t.timeoutMs;
|
|
977
|
+
return typeof e == "number" && Number.isFinite(e) && e > 0 && e <= 2147483647 ? e : 6e5;
|
|
978
|
+
}
|
|
979
|
+
var at, F, se, Te, Ce, Z, q, Oe, Be, ze, dt, I, jt, we, Ot, je, Bt, bt = class {
|
|
980
|
+
constructor(e, n, o, i, s, d) {
|
|
981
|
+
this.role = e;
|
|
982
|
+
this.remote = n;
|
|
983
|
+
this.penpal = o;
|
|
984
|
+
this.port = i;
|
|
985
|
+
this.modules = s;
|
|
986
|
+
this.operationTimeoutMs = d;
|
|
987
|
+
p(this, I);
|
|
988
|
+
p(this, at, new AbortController());
|
|
989
|
+
p(this, F, /* @__PURE__ */ new Map());
|
|
990
|
+
p(this, se, /* @__PURE__ */ new Map());
|
|
991
|
+
p(this, Te, /* @__PURE__ */ new Map());
|
|
992
|
+
p(this, Ce, /* @__PURE__ */ new Map());
|
|
993
|
+
p(this, Z, /* @__PURE__ */ new Map());
|
|
994
|
+
p(this, q, /* @__PURE__ */ new Map());
|
|
995
|
+
p(this, Oe, /* @__PURE__ */ new Set());
|
|
996
|
+
p(this, Be);
|
|
997
|
+
p(this, ze, !1);
|
|
998
|
+
p(this, dt, !1);
|
|
999
|
+
}
|
|
1000
|
+
role;
|
|
1001
|
+
remote;
|
|
1002
|
+
penpal;
|
|
1003
|
+
port;
|
|
1004
|
+
modules;
|
|
1005
|
+
operationTimeoutMs;
|
|
1006
|
+
get closed() {
|
|
1007
|
+
return r(this, ze);
|
|
1008
|
+
}
|
|
1009
|
+
get closeSignal() {
|
|
1010
|
+
return r(this, at).signal;
|
|
1011
|
+
}
|
|
1012
|
+
attachHeartbeat(e) {
|
|
1013
|
+
if (this.closed) {
|
|
1014
|
+
e.stop();
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
l(this, Be, e), e.start();
|
|
1018
|
+
}
|
|
1019
|
+
// `operation` names the outbound message for diagnostics only; a failure
|
|
1020
|
+
// here closes the connection without telling the peer why.
|
|
1021
|
+
send(e, n) {
|
|
1022
|
+
if (this.closed)
|
|
1023
|
+
return;
|
|
1024
|
+
let o;
|
|
1025
|
+
try {
|
|
1026
|
+
o = n();
|
|
1027
|
+
} catch (d) {
|
|
1028
|
+
y("an outbound embedding message could not be sent", {
|
|
1029
|
+
side: this.role,
|
|
1030
|
+
operation: e,
|
|
1031
|
+
cause: S(d)
|
|
1032
|
+
}), this.noteDisconnected();
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
let i = globalThis.setTimeout(
|
|
1036
|
+
() => {
|
|
1037
|
+
r(this, Oe).delete(i), y(
|
|
1038
|
+
"an outbound embedding message was never acknowledged; closing the connection",
|
|
1039
|
+
{
|
|
1040
|
+
side: this.role,
|
|
1041
|
+
operation: e,
|
|
1042
|
+
timeoutMs: this.operationTimeoutMs
|
|
1043
|
+
}
|
|
1044
|
+
), this.close();
|
|
1045
|
+
},
|
|
1046
|
+
Math.max(0, this.operationTimeoutMs)
|
|
1047
|
+
);
|
|
1048
|
+
r(this, Oe).add(i);
|
|
1049
|
+
let s = (d, c) => {
|
|
1050
|
+
r(this, Oe).delete(i) && (globalThis.clearTimeout(i), d && (y("an outbound embedding message was rejected", {
|
|
1051
|
+
side: this.role,
|
|
1052
|
+
operation: e,
|
|
1053
|
+
cause: S(c)
|
|
1054
|
+
}), this.noteDisconnected()));
|
|
1055
|
+
};
|
|
1056
|
+
o.then(
|
|
1057
|
+
() => s(!1),
|
|
1058
|
+
(d) => s(!0, d)
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
// `notifyPeer` defaults to false to match every existing call site: an
|
|
1062
|
+
// outbound send/call that itself failed or was rejected implies the
|
|
1063
|
+
// transport is already broken, so attempting another outbound message
|
|
1064
|
+
// to notify the peer would be pointless (and could throw again). The
|
|
1065
|
+
// one caller that passes `true` is a heartbeat's locally-detected peer
|
|
1066
|
+
// loss (see establish.ts): a missed probe doesn't imply postMessage
|
|
1067
|
+
// itself is broken, only that the peer's own process may be
|
|
1068
|
+
// unresponsive, so there's still a reasonable chance a close
|
|
1069
|
+
// notification actually gets through -- worth attempting, and this
|
|
1070
|
+
// reuses close()'s already-tested immediate-semantic/delayed-transport
|
|
1071
|
+
// split rather than approximating it separately.
|
|
1072
|
+
noteDisconnected(e = !1) {
|
|
1073
|
+
this.close(e);
|
|
1074
|
+
}
|
|
1075
|
+
// The endpoint owns every subscription, timer, claim and port. Teardown is
|
|
1076
|
+
// idempotent because disconnect, explicit close and heartbeat may race.
|
|
1077
|
+
close(e = !0) {
|
|
1078
|
+
if (r(this, ze))
|
|
1079
|
+
return;
|
|
1080
|
+
l(this, ze, !0);
|
|
1081
|
+
let n;
|
|
1082
|
+
if (e) {
|
|
1083
|
+
rt(this.port);
|
|
1084
|
+
try {
|
|
1085
|
+
n = this.remote.__ddClose();
|
|
1086
|
+
} catch {
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
r(this, Be)?.stop(), l(this, Be, void 0);
|
|
1090
|
+
for (let o of r(this, Oe))
|
|
1091
|
+
globalThis.clearTimeout(o);
|
|
1092
|
+
r(this, Oe).clear(), r(this, at).abort();
|
|
1093
|
+
for (let o of [...r(this, F).keys()])
|
|
1094
|
+
this.receiveRelease(o);
|
|
1095
|
+
for (let [o, i] of [...r(this, Te).entries()])
|
|
1096
|
+
a(this, I, je).call(this, o, i, { code: "DISCONNECTED" }, !1);
|
|
1097
|
+
if (r(this, Ce).clear(), r(this, Z).clear(), r(this, q).clear(), !e) {
|
|
1098
|
+
a(this, I, jt).call(this);
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
n?.catch(() => {
|
|
1102
|
+
}), globalThis.setTimeout(
|
|
1103
|
+
() => a(this, I, jt).call(this),
|
|
1104
|
+
xe
|
|
1105
|
+
);
|
|
1106
|
+
}
|
|
1107
|
+
async settleRemoteResult(e, n) {
|
|
1108
|
+
return this.closed ? (e.then(
|
|
1109
|
+
(o) => {
|
|
1110
|
+
n.onDiscardedResult?.(o);
|
|
1111
|
+
},
|
|
1112
|
+
() => {
|
|
1113
|
+
}
|
|
1114
|
+
), u(n.disconnectedError)) : new Promise((o) => {
|
|
1115
|
+
let i = !1, s, d = (f) => {
|
|
1116
|
+
i || (i = !0, s !== void 0 && globalThis.clearTimeout(s), n.signal?.removeEventListener("abort", c), this.closeSignal.removeEventListener("abort", h), o(f));
|
|
1117
|
+
}, c = () => {
|
|
1118
|
+
n.onCancel(), d(u(n.abortError));
|
|
1119
|
+
}, h = () => d(u(n.disconnectedError));
|
|
1120
|
+
if (n.signal?.addEventListener("abort", c, { once: !0 }), this.closeSignal.addEventListener("abort", h, {
|
|
1121
|
+
once: !0
|
|
1122
|
+
}), n.signal?.aborted) {
|
|
1123
|
+
c();
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
if (this.closeSignal.aborted) {
|
|
1127
|
+
h();
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
s = globalThis.setTimeout(
|
|
1131
|
+
() => {
|
|
1132
|
+
n.onCancel(), d(u(n.timeoutError(n.timeoutMs)));
|
|
1133
|
+
},
|
|
1134
|
+
Math.max(0, n.timeoutMs)
|
|
1135
|
+
), e.then(
|
|
1136
|
+
(f) => {
|
|
1137
|
+
if (i) {
|
|
1138
|
+
n.onDiscardedResult?.(f);
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
if (b(f) && f.ok === !0) {
|
|
1142
|
+
d(P(f.value));
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
n.onDiscardedResult?.(f), d(
|
|
1146
|
+
u(
|
|
1147
|
+
n.normalize(
|
|
1148
|
+
b(f) ? f.error : f
|
|
1149
|
+
)
|
|
1150
|
+
)
|
|
1151
|
+
);
|
|
1152
|
+
},
|
|
1153
|
+
() => {
|
|
1154
|
+
this.noteDisconnected(), d(u(n.disconnectedError));
|
|
1155
|
+
}
|
|
1156
|
+
);
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
async claim(e, n = {}) {
|
|
1160
|
+
if (this.closed)
|
|
1161
|
+
return u({ code: "DISCONNECTED" });
|
|
1162
|
+
if (n.signal?.aborted)
|
|
1163
|
+
return u({ code: "ABORTED" });
|
|
1164
|
+
let o = n.timeoutMs ?? 5e3;
|
|
1165
|
+
qe("ClaimOptions.timeoutMs", o);
|
|
1166
|
+
let i = me("claim");
|
|
1167
|
+
r(this, Ce).set(i, e);
|
|
1168
|
+
let s;
|
|
1169
|
+
try {
|
|
1170
|
+
s = this.remote.__ddClaim({
|
|
1171
|
+
claimId: i,
|
|
1172
|
+
identifier: e.identifier,
|
|
1173
|
+
version: e.version,
|
|
1174
|
+
fields: Object.keys(e.fields)
|
|
1175
|
+
});
|
|
1176
|
+
} catch (O) {
|
|
1177
|
+
return y("a claim could not be sent to the Datadog host", {
|
|
1178
|
+
side: this.role,
|
|
1179
|
+
claimId: i,
|
|
1180
|
+
identifier: e.identifier,
|
|
1181
|
+
version: e.version,
|
|
1182
|
+
cause: S(O)
|
|
1183
|
+
}), a(this, I, we).call(this, i), this.noteDisconnected(), u({ code: "DISCONNECTED" });
|
|
1184
|
+
}
|
|
1185
|
+
s = s.then(
|
|
1186
|
+
(O) => O,
|
|
1187
|
+
() => (this.noteDisconnected(), u({ code: "DISCONNECTED" }))
|
|
1188
|
+
);
|
|
1189
|
+
let d = await this.settleRemoteResult(s, {
|
|
1190
|
+
timeoutMs: o,
|
|
1191
|
+
signal: n.signal,
|
|
1192
|
+
onCancel: () => {
|
|
1193
|
+
this.send(
|
|
1194
|
+
"__ddRelease",
|
|
1195
|
+
() => this.remote.__ddRelease(i)
|
|
1196
|
+
);
|
|
1197
|
+
},
|
|
1198
|
+
timeoutError: (O) => ({
|
|
1199
|
+
code: "TIMED_OUT",
|
|
1200
|
+
timeoutMs: O
|
|
1201
|
+
}),
|
|
1202
|
+
abortError: { code: "ABORTED" },
|
|
1203
|
+
disconnectedError: { code: "DISCONNECTED" },
|
|
1204
|
+
normalize: (O) => Ct(O, [
|
|
1205
|
+
"PEER_LACKS_MODULE",
|
|
1206
|
+
"APP_MAJOR_TOO_OLD",
|
|
1207
|
+
"HOST_MAJOR_TOO_OLD",
|
|
1208
|
+
"CONTRACT_INCOMPATIBLE",
|
|
1209
|
+
"INVALID_RESULT",
|
|
1210
|
+
"TIMED_OUT",
|
|
1211
|
+
"ABORTED",
|
|
1212
|
+
"DISCONNECTED",
|
|
1213
|
+
"UNRECOGNIZED"
|
|
1214
|
+
])
|
|
1215
|
+
});
|
|
1216
|
+
if (!d.ok)
|
|
1217
|
+
return a(this, I, we).call(this, i), d;
|
|
1218
|
+
if (!b(d.value) || !b(d.value.values))
|
|
1219
|
+
return a(this, I, we).call(this, i), this.send("__ddRelease", () => this.remote.__ddRelease(i)), u({
|
|
1220
|
+
code: "INVALID_RESULT",
|
|
1221
|
+
issues: [
|
|
1222
|
+
{ message: "Malformed claim success payload.", path: [] }
|
|
1223
|
+
]
|
|
1224
|
+
});
|
|
1225
|
+
let c = Et(
|
|
1226
|
+
gt(e),
|
|
1227
|
+
d.value.values
|
|
1228
|
+
);
|
|
1229
|
+
if (c)
|
|
1230
|
+
return a(this, I, we).call(this, i), this.send("__ddRelease", () => this.remote.__ddRelease(i)), u(c);
|
|
1231
|
+
let h = /* @__PURE__ */ new Map(), f = {}, m = {
|
|
1232
|
+
contract: e,
|
|
1233
|
+
values: h,
|
|
1234
|
+
valueListeners: /* @__PURE__ */ new Set(),
|
|
1235
|
+
invalidationListeners: /* @__PURE__ */ new Set(),
|
|
1236
|
+
releaseController: new AbortController(),
|
|
1237
|
+
released: !1,
|
|
1238
|
+
// The claim response above already seeded every field, but that
|
|
1239
|
+
// is a separate channel from __ddValues: the first message on
|
|
1240
|
+
// this channel still has to prove it is complete.
|
|
1241
|
+
hydrated: !1
|
|
1242
|
+
};
|
|
1243
|
+
for (let [O, D] of Object.entries(e.fields)) {
|
|
1244
|
+
if (D.kind === "function") {
|
|
1245
|
+
f[O] = (...T) => this.callFunction(i, m, O, D, T);
|
|
1246
|
+
continue;
|
|
1247
|
+
}
|
|
1248
|
+
let H = Pe(D.schema, d.value.values[O]);
|
|
1249
|
+
if (!H.ok)
|
|
1250
|
+
return a(this, I, we).call(this, i), this.send(
|
|
1251
|
+
"__ddRelease",
|
|
1252
|
+
() => this.remote.__ddRelease(i)
|
|
1253
|
+
), u({
|
|
1254
|
+
code: "INVALID_RESULT",
|
|
1255
|
+
issues: He(O, H.error)
|
|
1256
|
+
});
|
|
1257
|
+
let M = new Ht(H.value);
|
|
1258
|
+
h.set(O, M), f[O] = M;
|
|
1259
|
+
}
|
|
1260
|
+
r(this, Te).set(i, m);
|
|
1261
|
+
let C = r(this, Z).get(i);
|
|
1262
|
+
C && this.receiveValues(i, C);
|
|
1263
|
+
let _ = m.invalidation ?? r(this, q).get(i);
|
|
1264
|
+
return a(this, I, we).call(this, i), _ ? (a(this, I, Ot).call(this, i, m, !0, _), u(_)) : P({
|
|
1265
|
+
fields: f,
|
|
1266
|
+
release: () => a(this, I, Ot).call(this, i, m, !0),
|
|
1267
|
+
onValuesChanged: (O) => m.released ? () => {
|
|
1268
|
+
} : (m.valueListeners.add(O), () => m.valueListeners.delete(O)),
|
|
1269
|
+
onInvalidated: (O) => {
|
|
1270
|
+
let D = m.invalidation;
|
|
1271
|
+
return D ? (globalThis.queueMicrotask(() => O(D)), () => {
|
|
1272
|
+
}) : m.released ? () => {
|
|
1273
|
+
} : (m.invalidationListeners.add(O), () => m.invalidationListeners.delete(O));
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
async callFunction(e, n, o, i, s) {
|
|
1278
|
+
if (this.closed)
|
|
1279
|
+
throw Ee(n.contract, o, {
|
|
1280
|
+
code: "DISCONNECTED"
|
|
1281
|
+
});
|
|
1282
|
+
if (n.released)
|
|
1283
|
+
throw Ee(n.contract, o, {
|
|
1284
|
+
code: "ABORTED"
|
|
1285
|
+
});
|
|
1286
|
+
if (s.length !== 1)
|
|
1287
|
+
throw Ee(n.contract, o, {
|
|
1288
|
+
code: "INVALID_ARGUMENT",
|
|
1289
|
+
issues: [
|
|
1290
|
+
{
|
|
1291
|
+
message: `Expected one named inputs object, received ${s.length} arguments.`,
|
|
1292
|
+
path: [o, "inputs"]
|
|
1293
|
+
}
|
|
1294
|
+
]
|
|
1295
|
+
});
|
|
1296
|
+
let d = Vt(
|
|
1297
|
+
o,
|
|
1298
|
+
i,
|
|
1299
|
+
s[0]
|
|
1300
|
+
);
|
|
1301
|
+
if (!d.ok)
|
|
1302
|
+
throw Ee(n.contract, o, {
|
|
1303
|
+
code: "INVALID_ARGUMENT",
|
|
1304
|
+
issues: d.error
|
|
1305
|
+
});
|
|
1306
|
+
let c = me("call"), h;
|
|
1307
|
+
try {
|
|
1308
|
+
h = this.remote.__ddCall({
|
|
1309
|
+
claimId: e,
|
|
1310
|
+
callId: c,
|
|
1311
|
+
field: o,
|
|
1312
|
+
inputs: d.value
|
|
1313
|
+
});
|
|
1314
|
+
} catch {
|
|
1315
|
+
throw this.noteDisconnected(), Ee(n.contract, o, {
|
|
1316
|
+
code: "DISCONNECTED"
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
let f = await this.settleRemoteResult(h, {
|
|
1320
|
+
// Independent of the host's own execution deadline and of this
|
|
1321
|
+
// endpoint's generic `operationTimeoutMs`.
|
|
1322
|
+
timeoutMs: Xn(i),
|
|
1323
|
+
signal: n.releaseController.signal,
|
|
1324
|
+
onCancel: () => {
|
|
1325
|
+
this.send(
|
|
1326
|
+
"__ddCancel",
|
|
1327
|
+
() => this.remote.__ddCancel({ claimId: e, callId: c })
|
|
1328
|
+
);
|
|
1329
|
+
},
|
|
1330
|
+
timeoutError: (C) => ({ code: "TIMED_OUT", timeoutMs: C }),
|
|
1331
|
+
abortError: { code: "ABORTED" },
|
|
1332
|
+
disconnectedError: { code: "DISCONNECTED" },
|
|
1333
|
+
normalize: (C) => Ct(C, [
|
|
1334
|
+
"CONTRACT_INCOMPATIBLE",
|
|
1335
|
+
"INVALID_ARGUMENT",
|
|
1336
|
+
"FUNCTION_FAILED",
|
|
1337
|
+
"INVALID_RESULT",
|
|
1338
|
+
"TIMED_OUT",
|
|
1339
|
+
"ABORTED",
|
|
1340
|
+
"DISCONNECTED",
|
|
1341
|
+
"UNRECOGNIZED"
|
|
1342
|
+
]),
|
|
1343
|
+
// onDiscardedResult receives the raw wire Result envelope, not
|
|
1344
|
+
// the unwrapped value discardFunctionResult expects -- only a
|
|
1345
|
+
// successful result can carry a MessagePort to close.
|
|
1346
|
+
onDiscardedResult: (C) => {
|
|
1347
|
+
b(C) && C.ok === !0 && st(C.value);
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
if (!f.ok) {
|
|
1351
|
+
let C = f.error.code === "INVALID_ARGUMENT" ? { code: "CONTRACT_INCOMPATIBLE", field: o } : f.error;
|
|
1352
|
+
throw Ee(n.contract, o, C);
|
|
1353
|
+
}
|
|
1354
|
+
let m = Wn(
|
|
1355
|
+
o,
|
|
1356
|
+
i,
|
|
1357
|
+
f.value
|
|
1358
|
+
);
|
|
1359
|
+
if (!m.ok)
|
|
1360
|
+
throw Ee(n.contract, o, {
|
|
1361
|
+
code: "INVALID_RESULT",
|
|
1362
|
+
issues: m.error
|
|
1363
|
+
});
|
|
1364
|
+
return m.value;
|
|
1365
|
+
}
|
|
1366
|
+
receiveValues(e, n) {
|
|
1367
|
+
if (!k(e, B)) {
|
|
1368
|
+
y(
|
|
1369
|
+
"ignored a __ddValues envelope with an invalid claim id",
|
|
1370
|
+
{
|
|
1371
|
+
side: this.role,
|
|
1372
|
+
claimId: e,
|
|
1373
|
+
maxClaimIdLength: B
|
|
1374
|
+
}
|
|
1375
|
+
);
|
|
1376
|
+
return;
|
|
1377
|
+
}
|
|
1378
|
+
let o = r(this, Te).get(e), i = r(this, Ce).get(e);
|
|
1379
|
+
if (!b(n)) {
|
|
1380
|
+
let h = {
|
|
1381
|
+
code: "INVALID_RESULT",
|
|
1382
|
+
issues: [
|
|
1383
|
+
{
|
|
1384
|
+
message: "The host value snapshot must be an object.",
|
|
1385
|
+
path: []
|
|
1386
|
+
}
|
|
1387
|
+
]
|
|
1388
|
+
};
|
|
1389
|
+
o ? a(this, I, je).call(this, e, o, h, !0) : i ? (r(this, q).set(e, h), r(this, Z).delete(e)) : y(
|
|
1390
|
+
"ignored a __ddValues envelope for an unknown claim",
|
|
1391
|
+
{
|
|
1392
|
+
side: this.role,
|
|
1393
|
+
claimId: e,
|
|
1394
|
+
receivedValues: typeof n
|
|
1395
|
+
}
|
|
1396
|
+
);
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1399
|
+
if (!o) {
|
|
1400
|
+
if (!i)
|
|
1401
|
+
return;
|
|
1402
|
+
let f = r(this, Z).has(e) ? kt(
|
|
1403
|
+
gt(i),
|
|
1404
|
+
n
|
|
1405
|
+
) : Et(
|
|
1406
|
+
gt(i),
|
|
1407
|
+
n
|
|
1408
|
+
);
|
|
1409
|
+
if (f) {
|
|
1410
|
+
r(this, q).set(e, f), r(this, Z).delete(e);
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
if (!r(this, q).has(e)) {
|
|
1414
|
+
let m = r(this, Z).get(e);
|
|
1415
|
+
r(this, Z).set(
|
|
1416
|
+
e,
|
|
1417
|
+
Object.freeze({ ...m, ...n })
|
|
1418
|
+
);
|
|
1419
|
+
}
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
let s = o.hydrated ? kt(o.values.keys(), n) : Et(o.values.keys(), n);
|
|
1423
|
+
if (s) {
|
|
1424
|
+
a(this, I, je).call(this, e, o, s, !0);
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
o.hydrated = !0;
|
|
1428
|
+
let d = [];
|
|
1429
|
+
for (let [h, f] of Object.entries(n)) {
|
|
1430
|
+
let m = o.values.get(h), C = o.contract.fields[h];
|
|
1431
|
+
if (!m || !C || C.kind !== "value")
|
|
1432
|
+
continue;
|
|
1433
|
+
let _ = Pe(C.schema, f);
|
|
1434
|
+
if (!_.ok) {
|
|
1435
|
+
let O = {
|
|
1436
|
+
code: "INVALID_RESULT",
|
|
1437
|
+
issues: He(h, _.error)
|
|
1438
|
+
};
|
|
1439
|
+
a(this, I, je).call(this, e, o, O, !0);
|
|
1440
|
+
return;
|
|
1441
|
+
}
|
|
1442
|
+
d.push([m, _.value]);
|
|
1443
|
+
}
|
|
1444
|
+
let c = [];
|
|
1445
|
+
for (let [h, f] of d)
|
|
1446
|
+
h.set(f) && c.push(h);
|
|
1447
|
+
for (let h of c)
|
|
1448
|
+
h.notify();
|
|
1449
|
+
c.length > 0 && ge(o.valueListeners);
|
|
1450
|
+
}
|
|
1451
|
+
receiveInvalidation(e, n) {
|
|
1452
|
+
if (!k(e, B)) {
|
|
1453
|
+
y(
|
|
1454
|
+
"ignored a __ddInvalidate envelope with an invalid claim id",
|
|
1455
|
+
{
|
|
1456
|
+
side: this.role,
|
|
1457
|
+
claimId: e,
|
|
1458
|
+
maxClaimIdLength: B
|
|
1459
|
+
}
|
|
1460
|
+
);
|
|
1461
|
+
return;
|
|
1462
|
+
}
|
|
1463
|
+
let o = Ct(n, [
|
|
1464
|
+
"INVALID_RESULT",
|
|
1465
|
+
"UNRECOGNIZED"
|
|
1466
|
+
]), i = r(this, Te).get(e);
|
|
1467
|
+
if (i) {
|
|
1468
|
+
a(this, I, je).call(this, e, i, o, !1);
|
|
1469
|
+
return;
|
|
1470
|
+
}
|
|
1471
|
+
r(this, Ce).has(e) && r(this, q).set(e, o);
|
|
1472
|
+
}
|
|
1473
|
+
async receiveClaim(e) {
|
|
1474
|
+
if (this.closed)
|
|
1475
|
+
return u({ code: "DISCONNECTED" });
|
|
1476
|
+
let n = Jn(e);
|
|
1477
|
+
if (n)
|
|
1478
|
+
return u(n);
|
|
1479
|
+
if (r(this, F).has(e.claimId))
|
|
1480
|
+
return u({
|
|
1481
|
+
code: "INVALID_RESULT",
|
|
1482
|
+
issues: [
|
|
1483
|
+
{
|
|
1484
|
+
message: `Claim id "${e.claimId}" is already live.`,
|
|
1485
|
+
path: ["claimId"]
|
|
1486
|
+
}
|
|
1487
|
+
]
|
|
1488
|
+
});
|
|
1489
|
+
if (r(this, F).size >= It)
|
|
1490
|
+
return u({
|
|
1491
|
+
code: "INVALID_RESULT",
|
|
1492
|
+
issues: [
|
|
1493
|
+
{
|
|
1494
|
+
message: `The peer exceeded the limit of ${It} simultaneous claims.`,
|
|
1495
|
+
path: ["claimId"]
|
|
1496
|
+
}
|
|
1497
|
+
]
|
|
1498
|
+
});
|
|
1499
|
+
let o = this.modules.filter(
|
|
1500
|
+
({ contract: T }) => T.identifier === e.identifier
|
|
1501
|
+
);
|
|
1502
|
+
if (o.length === 0)
|
|
1503
|
+
return u({
|
|
1504
|
+
code: "PEER_LACKS_MODULE",
|
|
1505
|
+
identifier: e.identifier
|
|
1506
|
+
});
|
|
1507
|
+
let i = Ft(
|
|
1508
|
+
e.version,
|
|
1509
|
+
o.map((T) => ({
|
|
1510
|
+
version: T.contract.version,
|
|
1511
|
+
module: T
|
|
1512
|
+
}))
|
|
1513
|
+
);
|
|
1514
|
+
if (!i.ok)
|
|
1515
|
+
return i;
|
|
1516
|
+
let s = i.value.module;
|
|
1517
|
+
if (s.signal?.aborted)
|
|
1518
|
+
return u({
|
|
1519
|
+
code: "INVALID_RESULT",
|
|
1520
|
+
issues: [
|
|
1521
|
+
{
|
|
1522
|
+
message: `The host provider for "${e.identifier}" is disposed.`,
|
|
1523
|
+
path: []
|
|
1524
|
+
}
|
|
1525
|
+
]
|
|
1526
|
+
});
|
|
1527
|
+
let d = /* @__PURE__ */ new Map(), c = {
|
|
1528
|
+
releases: [],
|
|
1529
|
+
module: s,
|
|
1530
|
+
fields: d
|
|
1531
|
+
};
|
|
1532
|
+
if (r(this, F).set(e.claimId, c), s.signal) {
|
|
1533
|
+
let T = () => a(this, I, Bt).call(this, e.claimId, [
|
|
1534
|
+
{
|
|
1535
|
+
message: `The host provider for "${e.identifier}" was disposed.`,
|
|
1536
|
+
path: []
|
|
1537
|
+
}
|
|
1538
|
+
]);
|
|
1539
|
+
s.signal.addEventListener("abort", T, {
|
|
1540
|
+
once: !0
|
|
1541
|
+
}), c.releases.push(
|
|
1542
|
+
() => s.signal?.removeEventListener("abort", T)
|
|
1543
|
+
);
|
|
1544
|
+
}
|
|
1545
|
+
let h = {}, f = { ready: !1 }, m = !1, C = !1, _ = !1, O = /* @__PURE__ */ new Set(), D = /* @__PURE__ */ new Map(), H = () => {
|
|
1546
|
+
if (C = !1, !r(this, F).has(e.claimId))
|
|
1547
|
+
return;
|
|
1548
|
+
let T = !_;
|
|
1549
|
+
if (!T && O.size === 0)
|
|
1550
|
+
return;
|
|
1551
|
+
let A = T ? [...D.keys()] : [...O];
|
|
1552
|
+
_ = !0, O.clear();
|
|
1553
|
+
let U = {};
|
|
1554
|
+
for (let W of A) {
|
|
1555
|
+
let oe = D.get(W);
|
|
1556
|
+
if (!oe)
|
|
1557
|
+
continue;
|
|
1558
|
+
let j = Ut(
|
|
1559
|
+
W,
|
|
1560
|
+
oe.field.schema,
|
|
1561
|
+
oe.provider
|
|
1562
|
+
);
|
|
1563
|
+
if (!j.ok) {
|
|
1564
|
+
a(this, I, Bt).call(this, e.claimId, Tt(
|
|
1565
|
+
e.identifier,
|
|
1566
|
+
W,
|
|
1567
|
+
j.error
|
|
1568
|
+
));
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
U[W] = j.value;
|
|
1572
|
+
}
|
|
1573
|
+
this.send(
|
|
1574
|
+
"__ddValues",
|
|
1575
|
+
() => this.remote.__ddValues(e.claimId, U)
|
|
1576
|
+
);
|
|
1577
|
+
}, M = () => {
|
|
1578
|
+
if (r(this, F).has(e.claimId)) {
|
|
1579
|
+
if (!f.ready) {
|
|
1580
|
+
m = !0;
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
C || (C = !0, globalThis.queueMicrotask(H));
|
|
1584
|
+
}
|
|
1585
|
+
};
|
|
1586
|
+
for (let T of e.fields) {
|
|
1587
|
+
let A = s.contract.fields[T];
|
|
1588
|
+
if (!A)
|
|
1589
|
+
return this.receiveRelease(e.claimId), u({ code: "CONTRACT_INCOMPATIBLE", field: T });
|
|
1590
|
+
if (d.set(T, A), A.kind === "function") {
|
|
1591
|
+
let j = Object.hasOwn(s.implementation, T) ? s.implementation[T] : void 0;
|
|
1592
|
+
if (!b(j) || typeof j.invoke != "function")
|
|
1593
|
+
return this.receiveRelease(e.claimId), u({
|
|
1594
|
+
code: "INVALID_RESULT",
|
|
1595
|
+
issues: [
|
|
1596
|
+
{
|
|
1597
|
+
message: "The host implementation is not a callable function field.",
|
|
1598
|
+
path: [T]
|
|
1599
|
+
}
|
|
1600
|
+
]
|
|
1601
|
+
});
|
|
1602
|
+
continue;
|
|
1603
|
+
}
|
|
1604
|
+
let U = Object.hasOwn(s.implementation, T) ? s.implementation[T] : void 0;
|
|
1605
|
+
if (!U || typeof U.get != "function" || typeof U.subscribe != "function")
|
|
1606
|
+
return this.receiveRelease(e.claimId), u({
|
|
1607
|
+
code: "INVALID_RESULT",
|
|
1608
|
+
issues: [
|
|
1609
|
+
{
|
|
1610
|
+
message: "The host implementation is not a live value.",
|
|
1611
|
+
path: [T]
|
|
1612
|
+
}
|
|
1613
|
+
]
|
|
1614
|
+
});
|
|
1615
|
+
D.set(T, { field: A, provider: U });
|
|
1616
|
+
let W;
|
|
1617
|
+
try {
|
|
1618
|
+
W = U.subscribe(() => {
|
|
1619
|
+
O.add(T), M();
|
|
1620
|
+
});
|
|
1621
|
+
} catch (j) {
|
|
1622
|
+
return this.receiveRelease(e.claimId), u({
|
|
1623
|
+
code: "INVALID_RESULT",
|
|
1624
|
+
issues: Tt(
|
|
1625
|
+
e.identifier,
|
|
1626
|
+
T,
|
|
1627
|
+
j
|
|
1628
|
+
)
|
|
1629
|
+
});
|
|
1630
|
+
}
|
|
1631
|
+
if (typeof W != "function")
|
|
1632
|
+
return this.receiveRelease(e.claimId), u({
|
|
1633
|
+
code: "INVALID_RESULT",
|
|
1634
|
+
issues: [
|
|
1635
|
+
{
|
|
1636
|
+
message: "The host value provider did not return an unsubscribe function.",
|
|
1637
|
+
path: [T]
|
|
1638
|
+
}
|
|
1639
|
+
]
|
|
1640
|
+
});
|
|
1641
|
+
if (r(this, F).get(e.claimId) !== c)
|
|
1642
|
+
return w(
|
|
1643
|
+
`unsubscribe for interrupted claim ${e.claimId}`,
|
|
1644
|
+
W
|
|
1645
|
+
), this.closed ? u({ code: "DISCONNECTED" }) : u({
|
|
1646
|
+
code: "INVALID_RESULT",
|
|
1647
|
+
issues: [
|
|
1648
|
+
{
|
|
1649
|
+
message: `The host provider for "${e.identifier}" was disposed during claim setup.`,
|
|
1650
|
+
path: []
|
|
1651
|
+
}
|
|
1652
|
+
]
|
|
1653
|
+
});
|
|
1654
|
+
c.releases.push(W);
|
|
1655
|
+
let oe = Ut(T, A.schema, U);
|
|
1656
|
+
if (!oe.ok)
|
|
1657
|
+
return this.receiveRelease(e.claimId), u({
|
|
1658
|
+
code: "INVALID_RESULT",
|
|
1659
|
+
issues: Tt(
|
|
1660
|
+
e.identifier,
|
|
1661
|
+
T,
|
|
1662
|
+
oe.error
|
|
1663
|
+
)
|
|
1664
|
+
});
|
|
1665
|
+
h[T] = oe.value;
|
|
1666
|
+
}
|
|
1667
|
+
return f.ready = !0, m && M(), P({ values: h });
|
|
1668
|
+
}
|
|
1669
|
+
async receiveFunctionCall(e) {
|
|
1670
|
+
if (this.closed)
|
|
1671
|
+
return u({ code: "DISCONNECTED" });
|
|
1672
|
+
let n = Kn(e);
|
|
1673
|
+
if (n)
|
|
1674
|
+
return u(n);
|
|
1675
|
+
let o = r(this, F).get(e.claimId);
|
|
1676
|
+
if (!o)
|
|
1677
|
+
return u({ code: "DISCONNECTED" });
|
|
1678
|
+
let i = o.fields.get(e.field);
|
|
1679
|
+
if (!i || i.kind !== "function")
|
|
1680
|
+
return u({
|
|
1681
|
+
code: "CONTRACT_INCOMPATIBLE",
|
|
1682
|
+
field: e.field
|
|
1683
|
+
});
|
|
1684
|
+
if (r(this, se).has(e.callId))
|
|
1685
|
+
return u({
|
|
1686
|
+
code: "INVALID_ARGUMENT",
|
|
1687
|
+
issues: [
|
|
1688
|
+
{
|
|
1689
|
+
message: `Function call id "${e.callId}" is already active.`,
|
|
1690
|
+
path: ["callId"]
|
|
1691
|
+
}
|
|
1692
|
+
]
|
|
1693
|
+
});
|
|
1694
|
+
if (xt >= bn)
|
|
1695
|
+
return u({
|
|
1696
|
+
code: "FUNCTION_FAILED",
|
|
1697
|
+
field: e.field
|
|
1698
|
+
});
|
|
1699
|
+
let s = Vt(
|
|
1700
|
+
e.field,
|
|
1701
|
+
i,
|
|
1702
|
+
e.inputs
|
|
1703
|
+
);
|
|
1704
|
+
if (!s.ok)
|
|
1705
|
+
return y("the host rejected the inputs of a function call", {
|
|
1706
|
+
side: this.role,
|
|
1707
|
+
claimId: e.claimId,
|
|
1708
|
+
callId: e.callId,
|
|
1709
|
+
target: `${o.module.contract.identifier}.${e.field}`,
|
|
1710
|
+
issueCount: s.error.length
|
|
1711
|
+
}), u({
|
|
1712
|
+
code: "INVALID_ARGUMENT",
|
|
1713
|
+
issues: [
|
|
1714
|
+
{
|
|
1715
|
+
message: "The function inputs do not satisfy the host schema.",
|
|
1716
|
+
path: [e.field, "inputs"]
|
|
1717
|
+
}
|
|
1718
|
+
]
|
|
1719
|
+
});
|
|
1720
|
+
let d = Object.hasOwn(
|
|
1721
|
+
o.module.implementation,
|
|
1722
|
+
e.field
|
|
1723
|
+
) ? o.module.implementation[e.field] : void 0;
|
|
1724
|
+
if (!b(d) || typeof d.invoke != "function")
|
|
1725
|
+
return u({
|
|
1726
|
+
code: "CONTRACT_INCOMPATIBLE",
|
|
1727
|
+
field: e.field
|
|
1728
|
+
});
|
|
1729
|
+
let c = new AbortController(), h = () => {
|
|
1730
|
+
}, f = new Promise((A) => {
|
|
1731
|
+
h = A;
|
|
1732
|
+
}), m = {
|
|
1733
|
+
claimId: e.claimId,
|
|
1734
|
+
controller: c,
|
|
1735
|
+
interrupt(A) {
|
|
1736
|
+
c.signal.aborted || (c.abort(), h({ status: "interrupted", reason: A }));
|
|
1737
|
+
}
|
|
1738
|
+
};
|
|
1739
|
+
xt += 1, r(this, se).set(e.callId, m);
|
|
1740
|
+
let C = Xn(i), _ = globalThis.performance.now() + C, O = globalThis.setTimeout(
|
|
1741
|
+
() => m.interrupt("timed-out"),
|
|
1742
|
+
C
|
|
1743
|
+
), D;
|
|
1744
|
+
try {
|
|
1745
|
+
let A = d.invoke(
|
|
1746
|
+
s.value,
|
|
1747
|
+
Object.freeze({ signal: c.signal })
|
|
1748
|
+
);
|
|
1749
|
+
globalThis.performance.now() >= _ && m.interrupt("timed-out"), D = Promise.resolve(A).then(
|
|
1750
|
+
(U) => globalThis.performance.now() >= _ ? (m.interrupt("timed-out"), st(U), { status: "interrupted", reason: "timed-out" }) : { status: "returned", value: U },
|
|
1751
|
+
(U) => globalThis.performance.now() >= _ ? (m.interrupt("timed-out"), { status: "interrupted", reason: "timed-out" }) : { status: "threw", cause: U }
|
|
1752
|
+
);
|
|
1753
|
+
} catch (A) {
|
|
1754
|
+
globalThis.performance.now() >= _ && m.interrupt("timed-out"), D = Promise.resolve({ status: "threw", cause: A });
|
|
1755
|
+
}
|
|
1756
|
+
let H = D.finally(() => {
|
|
1757
|
+
xt -= 1, r(this, se).get(e.callId) === m && r(this, se).delete(e.callId);
|
|
1758
|
+
}), M = await Promise.race([
|
|
1759
|
+
H,
|
|
1760
|
+
f
|
|
1761
|
+
]);
|
|
1762
|
+
if (globalThis.clearTimeout(O), M.status === "interrupted")
|
|
1763
|
+
return H.then((A) => {
|
|
1764
|
+
A.status === "returned" && st(A.value);
|
|
1765
|
+
}), M.reason === "timed-out" ? u({
|
|
1766
|
+
code: "TIMED_OUT",
|
|
1767
|
+
timeoutMs: C
|
|
1768
|
+
}) : u({ code: "DISCONNECTED" });
|
|
1769
|
+
if (this.closed || c.signal.aborted || r(this, F).get(e.claimId) !== o)
|
|
1770
|
+
return M.status === "returned" && st(M.value), u({ code: "DISCONNECTED" });
|
|
1771
|
+
if (M.status === "threw")
|
|
1772
|
+
return y("a host function implementation threw", {
|
|
1773
|
+
side: this.role,
|
|
1774
|
+
claimId: e.claimId,
|
|
1775
|
+
callId: e.callId,
|
|
1776
|
+
target: `${o.module.contract.identifier}.${e.field}`,
|
|
1777
|
+
cause: S(M.cause)
|
|
1778
|
+
}), u({
|
|
1779
|
+
code: "FUNCTION_FAILED",
|
|
1780
|
+
field: e.field
|
|
1781
|
+
});
|
|
1782
|
+
let T = zn(
|
|
1783
|
+
e.field,
|
|
1784
|
+
i,
|
|
1785
|
+
M.value
|
|
1786
|
+
);
|
|
1787
|
+
return T.ok ? T.value : (y("a host function returned an invalid result", {
|
|
1788
|
+
side: this.role,
|
|
1789
|
+
claimId: e.claimId,
|
|
1790
|
+
callId: e.callId,
|
|
1791
|
+
target: `${o.module.contract.identifier}.${e.field}`,
|
|
1792
|
+
issues: T.error
|
|
1793
|
+
}), u({
|
|
1794
|
+
code: "INVALID_RESULT",
|
|
1795
|
+
issues: [
|
|
1796
|
+
{
|
|
1797
|
+
message: "The host function returned a result that does not satisfy its schema.",
|
|
1798
|
+
path: [e.field]
|
|
1799
|
+
}
|
|
1800
|
+
]
|
|
1801
|
+
}));
|
|
1802
|
+
}
|
|
1803
|
+
receiveFunctionCancel(e) {
|
|
1804
|
+
if (!b(e) || !k(e.claimId, B) || !k(e.callId, tt)) {
|
|
1805
|
+
y("ignored a malformed __ddCancel envelope", {
|
|
1806
|
+
side: this.role,
|
|
1807
|
+
request: b(e) ? {
|
|
1808
|
+
claimId: e.claimId,
|
|
1809
|
+
callId: e.callId
|
|
1810
|
+
} : { malformed: !0, received: typeof e }
|
|
1811
|
+
});
|
|
1812
|
+
return;
|
|
1813
|
+
}
|
|
1814
|
+
let n = r(this, se).get(e.callId);
|
|
1815
|
+
n?.claimId === e.claimId && n.interrupt("cancelled");
|
|
1816
|
+
}
|
|
1817
|
+
receiveRelease(e) {
|
|
1818
|
+
if (!k(e, B)) {
|
|
1819
|
+
y("ignored a __ddRelease with an invalid claim id", {
|
|
1820
|
+
side: this.role,
|
|
1821
|
+
claimId: e,
|
|
1822
|
+
maxClaimIdLength: B
|
|
1823
|
+
});
|
|
1824
|
+
return;
|
|
1825
|
+
}
|
|
1826
|
+
let n = r(this, F).get(e);
|
|
1827
|
+
if (n) {
|
|
1828
|
+
r(this, F).delete(e);
|
|
1829
|
+
for (let o of r(this, se).values())
|
|
1830
|
+
o.claimId === e && o.interrupt("cancelled");
|
|
1831
|
+
for (let o of n.releases)
|
|
1832
|
+
w(`unsubscribe for claim ${e}`, o);
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
};
|
|
1836
|
+
at = new WeakMap(), F = new WeakMap(), se = new WeakMap(), Te = new WeakMap(), Ce = new WeakMap(), Z = new WeakMap(), q = new WeakMap(), Oe = new WeakMap(), Be = new WeakMap(), ze = new WeakMap(), dt = new WeakMap(), I = new WeakSet(), jt = function() {
|
|
1837
|
+
r(this, dt) || (l(this, dt, !0), w("Penpal connection", () => this.penpal.destroy()), w("operational port", () => this.port.close()));
|
|
1838
|
+
}, we = function(e) {
|
|
1839
|
+
r(this, Ce).delete(e), r(this, Z).delete(e), r(this, q).delete(e);
|
|
1840
|
+
}, Ot = function(e, n, o, i) {
|
|
1841
|
+
if (n.released)
|
|
1842
|
+
return !1;
|
|
1843
|
+
n.released = !0, n.invalidation = i, n.releaseController.abort();
|
|
1844
|
+
for (let s of n.values.values())
|
|
1845
|
+
s.freeze();
|
|
1846
|
+
return n.valueListeners.clear(), n.invalidationListeners.clear(), r(this, Te).delete(e), o && this.send("__ddRelease", () => this.remote.__ddRelease(e)), !0;
|
|
1847
|
+
}, je = function(e, n, o, i) {
|
|
1848
|
+
let s = [...n.invalidationListeners];
|
|
1849
|
+
if (!a(this, I, Ot).call(this, e, n, i, o))
|
|
1850
|
+
return;
|
|
1851
|
+
(o.code === "DISCONNECTED" ? x : y)("a live claim was invalidated", {
|
|
1852
|
+
side: this.role,
|
|
1853
|
+
claimId: e,
|
|
1854
|
+
identifier: n.contract.identifier,
|
|
1855
|
+
version: n.contract.version,
|
|
1856
|
+
observedListeners: s.length,
|
|
1857
|
+
error: J(o)
|
|
1858
|
+
}), ge(s, o);
|
|
1859
|
+
}, Bt = function(e, n) {
|
|
1860
|
+
let o = r(this, F).get(e);
|
|
1861
|
+
o && (y("the host invalidated a claim it was serving", {
|
|
1862
|
+
side: this.role,
|
|
1863
|
+
claimId: e,
|
|
1864
|
+
identifier: o.module.contract.identifier,
|
|
1865
|
+
version: o.module.contract.version,
|
|
1866
|
+
issues: n
|
|
1867
|
+
}), this.receiveRelease(e), this.send(
|
|
1868
|
+
"__ddInvalidate",
|
|
1869
|
+
() => this.remote.__ddInvalidate(e, {
|
|
1870
|
+
code: "INVALID_RESULT",
|
|
1871
|
+
issues: n
|
|
1872
|
+
})
|
|
1873
|
+
));
|
|
1874
|
+
};
|
|
1875
|
+
|
|
1876
|
+
// src/embedding/protocol/establish.ts
|
|
1877
|
+
function Fo(t, e) {
|
|
1878
|
+
if (!b(t))
|
|
1879
|
+
return { malformed: !0, received: typeof t };
|
|
1880
|
+
let n = {};
|
|
1881
|
+
for (let o of e)
|
|
1882
|
+
n[o] = t[o];
|
|
1883
|
+
return n;
|
|
1884
|
+
}
|
|
1885
|
+
var Wt = class {
|
|
1886
|
+
constructor(e, n) {
|
|
1887
|
+
this.endpoint = e;
|
|
1888
|
+
this.modules = n;
|
|
1889
|
+
}
|
|
1890
|
+
endpoint;
|
|
1891
|
+
modules;
|
|
1892
|
+
async claim(e, n) {
|
|
1893
|
+
if (this.endpoint.closed || n?.signal?.aborted)
|
|
1894
|
+
return this.endpoint.claim(e, n);
|
|
1895
|
+
qe(
|
|
1896
|
+
"ClaimOptions.timeoutMs",
|
|
1897
|
+
n?.timeoutMs ?? 5e3
|
|
1898
|
+
);
|
|
1899
|
+
let o = Zn(e, this.modules);
|
|
1900
|
+
return o ? Promise.resolve(u(o)) : this.endpoint.claim(e, n);
|
|
1901
|
+
}
|
|
1902
|
+
};
|
|
1903
|
+
function xo(t) {
|
|
1904
|
+
return b(t) && t.role === "host" && Array.isArray(t.modules);
|
|
1905
|
+
}
|
|
1906
|
+
function Ho(t) {
|
|
1907
|
+
let e = /* @__PURE__ */ new Set(), n = [];
|
|
1908
|
+
for (let o of t) {
|
|
1909
|
+
if (!b(o) || !k(o.identifier) || !De(o.version))
|
|
1910
|
+
continue;
|
|
1911
|
+
let i = JSON.stringify([o.identifier, o.version]);
|
|
1912
|
+
e.has(i) || (e.add(i), n.push({
|
|
1913
|
+
identifier: o.identifier,
|
|
1914
|
+
version: o.version
|
|
1915
|
+
}));
|
|
1916
|
+
}
|
|
1917
|
+
return n;
|
|
1918
|
+
}
|
|
1919
|
+
async function jo(t, e, n, o, i, s, d) {
|
|
1920
|
+
let c, h, f = !1, m = !1, C, _ = new Promise((g, R) => {
|
|
1921
|
+
C = R;
|
|
1922
|
+
});
|
|
1923
|
+
try {
|
|
1924
|
+
h = new mt(
|
|
1925
|
+
t,
|
|
1926
|
+
(g) => {
|
|
1927
|
+
c ? c.noteDisconnected(g) : (f = !0, g || t.close(), C?.({ code: "DISCONNECTED" }));
|
|
1928
|
+
},
|
|
1929
|
+
d,
|
|
1930
|
+
e
|
|
1931
|
+
);
|
|
1932
|
+
} catch (g) {
|
|
1933
|
+
return w("failed operational port", () => t.close()), u({ code: "TRANSPORT_FAILED", cause: g });
|
|
1934
|
+
}
|
|
1935
|
+
let O = !1, D = 0, H = () => {
|
|
1936
|
+
}, M = new Promise(
|
|
1937
|
+
(g) => {
|
|
1938
|
+
H = g;
|
|
1939
|
+
}
|
|
1940
|
+
), T = (g) => {
|
|
1941
|
+
O || (O = !0, H(g));
|
|
1942
|
+
}, A = (g, R) => {
|
|
1943
|
+
let N = (Y) => (x("an embedding operation was refused", {
|
|
1944
|
+
side: e,
|
|
1945
|
+
operation: R,
|
|
1946
|
+
expectedRole: g,
|
|
1947
|
+
reason: Y,
|
|
1948
|
+
pendingEndpointOperations: D
|
|
1949
|
+
}), new Error(Y));
|
|
1950
|
+
return c ? c.role === g ? Promise.resolve(c) : Promise.reject(
|
|
1951
|
+
N("The embedding operation is not valid here.")
|
|
1952
|
+
) : O || D >= yn ? Promise.reject(
|
|
1953
|
+
N("The embedding endpoint is not ready for work.")
|
|
1954
|
+
) : (D += 1, M.then((Y) => {
|
|
1955
|
+
if (!Y || Y.role !== g)
|
|
1956
|
+
throw N(
|
|
1957
|
+
"The embedding operation is not valid here."
|
|
1958
|
+
);
|
|
1959
|
+
return Y;
|
|
1960
|
+
}).finally(() => {
|
|
1961
|
+
D -= 1;
|
|
1962
|
+
}));
|
|
1963
|
+
}, U = e === "host" ? {
|
|
1964
|
+
role: "host",
|
|
1965
|
+
modules: i.map(({ contract: g }) => ({
|
|
1966
|
+
identifier: g.identifier,
|
|
1967
|
+
version: g.version
|
|
1968
|
+
})),
|
|
1969
|
+
surfaceId: s
|
|
1970
|
+
} : { role: "app" }, W = (g, R, N, Y) => (Y.ok || x(`${g} was rejected`, {
|
|
1971
|
+
side: e,
|
|
1972
|
+
request: Fo(R, N),
|
|
1973
|
+
error: J(Y.error)
|
|
1974
|
+
}), Y), oe = {
|
|
1975
|
+
__ddDescribe: () => U,
|
|
1976
|
+
__ddClaim: (g) => A("host", "__ddClaim").then(
|
|
1977
|
+
(R) => R.receiveClaim(g).then(
|
|
1978
|
+
(N) => W(
|
|
1979
|
+
"__ddClaim",
|
|
1980
|
+
g,
|
|
1981
|
+
["claimId", "identifier", "version", "fields"],
|
|
1982
|
+
N
|
|
1983
|
+
)
|
|
1984
|
+
)
|
|
1985
|
+
),
|
|
1986
|
+
__ddRelease: (g) => A("host", "__ddRelease").then(
|
|
1987
|
+
(R) => R.receiveRelease(g)
|
|
1988
|
+
),
|
|
1989
|
+
__ddValues: (g, R) => A("app", "__ddValues").then(
|
|
1990
|
+
(N) => N.receiveValues(g, R)
|
|
1991
|
+
),
|
|
1992
|
+
__ddCall: (g) => A("host", "__ddCall").then(
|
|
1993
|
+
(R) => R.receiveFunctionCall(g).then((N) => (W(
|
|
1994
|
+
"__ddCall",
|
|
1995
|
+
g,
|
|
1996
|
+
["claimId", "callId", "field"],
|
|
1997
|
+
N instanceof Vo ? N.value : N
|
|
1998
|
+
), N))
|
|
1999
|
+
),
|
|
2000
|
+
__ddCancel: (g) => A("host", "__ddCancel").then(
|
|
2001
|
+
(R) => R.receiveFunctionCancel(g)
|
|
2002
|
+
),
|
|
2003
|
+
__ddInvalidate: (g, R) => A("app", "__ddInvalidate").then(
|
|
2004
|
+
(N) => N.receiveInvalidation(g, R)
|
|
2005
|
+
),
|
|
2006
|
+
__ddClose: () => (c || (m = !0), A(e, "__ddClose").then(
|
|
2007
|
+
(g) => g.close(!1)
|
|
2008
|
+
))
|
|
2009
|
+
}, j;
|
|
2010
|
+
try {
|
|
2011
|
+
j = ko({
|
|
2012
|
+
messenger: new Uo({ port: t }),
|
|
2013
|
+
methods: oe,
|
|
2014
|
+
timeout: n
|
|
2015
|
+
});
|
|
2016
|
+
} catch (g) {
|
|
2017
|
+
return h.stop(), rt(t), globalThis.setTimeout(
|
|
2018
|
+
() => t.close(),
|
|
2019
|
+
xe
|
|
2020
|
+
), u({ code: "TRANSPORT_FAILED", cause: g });
|
|
2021
|
+
}
|
|
2022
|
+
let un, pn, hn = () => un?.({ code: "ABORTED" }), fn = new Promise((g, R) => {
|
|
2023
|
+
un = R;
|
|
2024
|
+
}), mn = new Promise((g, R) => {
|
|
2025
|
+
pn = R;
|
|
2026
|
+
}), mo = globalThis.setTimeout(
|
|
2027
|
+
() => pn?.({ code: "TIMED_OUT" }),
|
|
2028
|
+
Math.max(0, n)
|
|
2029
|
+
);
|
|
2030
|
+
o.addEventListener("abort", hn, { once: !0 });
|
|
2031
|
+
let At = "handshake";
|
|
2032
|
+
try {
|
|
2033
|
+
if (o.aborted)
|
|
2034
|
+
throw Object.assign(new Error("The connection was aborted."), {
|
|
2035
|
+
code: "ABORTED"
|
|
2036
|
+
});
|
|
2037
|
+
let g = await Promise.race([
|
|
2038
|
+
j.promise,
|
|
2039
|
+
fn,
|
|
2040
|
+
mn,
|
|
2041
|
+
_
|
|
2042
|
+
]);
|
|
2043
|
+
At = "peer-description";
|
|
2044
|
+
let R = await Promise.race([
|
|
2045
|
+
g.__ddDescribe(),
|
|
2046
|
+
fn,
|
|
2047
|
+
mn,
|
|
2048
|
+
_
|
|
2049
|
+
]);
|
|
2050
|
+
if (At = "validation", !(e === "app" ? xo(R) : b(R) && R.role === "app"))
|
|
2051
|
+
throw new Error(
|
|
2052
|
+
`Expected an embedding ${e === "app" ? "host" : "app"} using the operational protocol.`
|
|
2053
|
+
);
|
|
2054
|
+
if (c = new bt(
|
|
2055
|
+
e,
|
|
2056
|
+
g,
|
|
2057
|
+
j,
|
|
2058
|
+
t,
|
|
2059
|
+
i,
|
|
2060
|
+
n
|
|
2061
|
+
), f)
|
|
2062
|
+
throw Object.assign(
|
|
2063
|
+
new Error(
|
|
2064
|
+
"The transport disconnected before establishment completed."
|
|
2065
|
+
),
|
|
2066
|
+
{ code: "DISCONNECTED" }
|
|
2067
|
+
);
|
|
2068
|
+
if (m)
|
|
2069
|
+
throw Object.assign(
|
|
2070
|
+
new Error(
|
|
2071
|
+
"The peer requested to close before establishment completed."
|
|
2072
|
+
),
|
|
2073
|
+
{ code: "DISCONNECTED" }
|
|
2074
|
+
);
|
|
2075
|
+
return T(c), c.attachHeartbeat(h), P({
|
|
2076
|
+
endpoint: c,
|
|
2077
|
+
description: R
|
|
2078
|
+
});
|
|
2079
|
+
} catch (g) {
|
|
2080
|
+
let R = Gn(g, n);
|
|
2081
|
+
return x("the operational protocol could not be established", {
|
|
2082
|
+
side: e,
|
|
2083
|
+
stage: At,
|
|
2084
|
+
timeoutMs: n,
|
|
2085
|
+
describedPeer: !!c,
|
|
2086
|
+
error: J(R),
|
|
2087
|
+
cause: S(g)
|
|
2088
|
+
}), h.stop(), c ? c.close() : Fn(j, t), u(R);
|
|
2089
|
+
} finally {
|
|
2090
|
+
T(void 0), globalThis.clearTimeout(mo), o.removeEventListener("abort", hn);
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
function Bo(t) {
|
|
2094
|
+
let e = t.endpoint, n = t.description;
|
|
2095
|
+
return {
|
|
2096
|
+
connection: new Wt(
|
|
2097
|
+
e,
|
|
2098
|
+
Ho(n.modules)
|
|
2099
|
+
),
|
|
2100
|
+
surfaceId: typeof n.surfaceId == "string" ? n.surfaceId : void 0,
|
|
2101
|
+
closeSignal: e.closeSignal,
|
|
2102
|
+
close: () => e.close()
|
|
2103
|
+
};
|
|
2104
|
+
}
|
|
2105
|
+
async function Yn(t, e, n, o) {
|
|
2106
|
+
let i = await jo(
|
|
2107
|
+
t,
|
|
2108
|
+
"app",
|
|
2109
|
+
e,
|
|
2110
|
+
n,
|
|
2111
|
+
[],
|
|
2112
|
+
void 0,
|
|
2113
|
+
o
|
|
2114
|
+
);
|
|
2115
|
+
return i.ok ? P(Bo(i.value)) : i;
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
// src/embedding/connection.ts
|
|
2119
|
+
var $o = [1];
|
|
2120
|
+
async function Go(t, e, n = 1e4) {
|
|
2121
|
+
if (e.aborted)
|
|
2122
|
+
return t.close(), u({ code: "ABORTED" });
|
|
2123
|
+
let o = await Un(
|
|
2124
|
+
t,
|
|
2125
|
+
$o,
|
|
2126
|
+
n,
|
|
2127
|
+
e
|
|
2128
|
+
);
|
|
2129
|
+
return o.ok ? Yn(
|
|
2130
|
+
o.value.operationalPort,
|
|
2131
|
+
n,
|
|
2132
|
+
e,
|
|
2133
|
+
Vn
|
|
2134
|
+
) : o;
|
|
2135
|
+
}
|
|
2136
|
+
var We, $t = class {
|
|
2137
|
+
constructor() {
|
|
2138
|
+
p(this, We);
|
|
2139
|
+
}
|
|
2140
|
+
next() {
|
|
2141
|
+
let e = r(this, We) ?? Cn;
|
|
2142
|
+
return l(this, We, Math.min(e * 2, On)), e;
|
|
2143
|
+
}
|
|
2144
|
+
reset() {
|
|
2145
|
+
l(this, We, void 0);
|
|
2146
|
+
}
|
|
2147
|
+
};
|
|
2148
|
+
We = new WeakMap();
|
|
2149
|
+
function Jo() {
|
|
2150
|
+
return typeof globalThis.window < "u" && globalThis.window.parent !== globalThis.window;
|
|
2151
|
+
}
|
|
2152
|
+
function Ko(t) {
|
|
2153
|
+
switch (t.code) {
|
|
2154
|
+
case "TIMED_OUT":
|
|
2155
|
+
case "TRANSPORT_FAILED":
|
|
2156
|
+
case "DISCONNECTED":
|
|
2157
|
+
case "UNRECOGNIZED":
|
|
2158
|
+
return !0;
|
|
2159
|
+
case "ORIGIN_REJECTED":
|
|
2160
|
+
case "APP_PROTOCOL_TOO_OLD":
|
|
2161
|
+
case "HOST_PROTOCOL_TOO_OLD":
|
|
2162
|
+
case "PROTOCOL_INCOMPATIBLE":
|
|
2163
|
+
case "ABORTED":
|
|
2164
|
+
return !1;
|
|
2165
|
+
default:
|
|
2166
|
+
return t;
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
var ae, Se, ct, z, de, ee, ce, le, te, be, $e, ke, v, Qn, Jt, Kt, Zt, Xt, yt, qn, Ne, Gt = class {
|
|
2170
|
+
constructor() {
|
|
2171
|
+
p(this, v);
|
|
2172
|
+
p(this, ae, new AbortController());
|
|
2173
|
+
p(this, Se, /* @__PURE__ */ new Set());
|
|
2174
|
+
p(this, ct, new $t());
|
|
2175
|
+
p(this, z, { state: "connecting" });
|
|
2176
|
+
p(this, de);
|
|
2177
|
+
p(this, ee);
|
|
2178
|
+
p(this, ce);
|
|
2179
|
+
p(this, le);
|
|
2180
|
+
p(this, te);
|
|
2181
|
+
p(this, be, 0);
|
|
2182
|
+
p(this, $e, !1);
|
|
2183
|
+
p(this, ke, !1);
|
|
2184
|
+
if (!Jo()) {
|
|
2185
|
+
l(this, z, { state: "not-embedded" });
|
|
2186
|
+
return;
|
|
2187
|
+
}
|
|
2188
|
+
a(this, v, Xt).call(this), a(this, v, Jt).call(this);
|
|
2189
|
+
}
|
|
2190
|
+
getSnapshot() {
|
|
2191
|
+
return r(this, z);
|
|
2192
|
+
}
|
|
2193
|
+
subscribe(e) {
|
|
2194
|
+
return r(this, Se).add(e), () => {
|
|
2195
|
+
r(this, Se).delete(e);
|
|
2196
|
+
};
|
|
2197
|
+
}
|
|
2198
|
+
close() {
|
|
2199
|
+
if (r(this, z).state === "closed")
|
|
2200
|
+
return;
|
|
2201
|
+
r(this, ae).abort(), r(this, ee)?.abort(), l(this, ee, void 0), a(this, v, Zt).call(this), a(this, v, yt).call(this);
|
|
2202
|
+
let e = r(this, de);
|
|
2203
|
+
l(this, de, void 0), a(this, v, Ne).call(this, { state: "closed" }), e?.close(), r(this, Se).clear();
|
|
2204
|
+
}
|
|
2205
|
+
};
|
|
2206
|
+
ae = new WeakMap(), Se = new WeakMap(), ct = new WeakMap(), z = new WeakMap(), de = new WeakMap(), ee = new WeakMap(), ce = new WeakMap(), le = new WeakMap(), te = new WeakMap(), be = new WeakMap(), $e = new WeakMap(), ke = new WeakMap(), v = new WeakSet(), Qn = async function(e) {
|
|
2207
|
+
let n = await wn(
|
|
2208
|
+
globalThis.window,
|
|
2209
|
+
Ln,
|
|
2210
|
+
e
|
|
2211
|
+
);
|
|
2212
|
+
return n.ok ? Go(n.value, e) : n;
|
|
2213
|
+
}, Jt = async function() {
|
|
2214
|
+
if (r(this, ae).signal.aborted || r(this, ke) || r(this, $e) || r(this, de))
|
|
2215
|
+
return;
|
|
2216
|
+
l(this, $e, !0), l(this, be, r(this, be) + 1);
|
|
2217
|
+
let e = new AbortController();
|
|
2218
|
+
l(this, ee, e);
|
|
2219
|
+
let n;
|
|
2220
|
+
try {
|
|
2221
|
+
n = await a(this, v, Qn).call(this, e.signal);
|
|
2222
|
+
} catch (i) {
|
|
2223
|
+
n = {
|
|
2224
|
+
ok: !1,
|
|
2225
|
+
error: { code: "TRANSPORT_FAILED", cause: i }
|
|
2226
|
+
};
|
|
2227
|
+
}
|
|
2228
|
+
if (l(this, $e, !1), r(this, ee) === e && l(this, ee, void 0), r(this, ae).signal.aborted || r(this, ke)) {
|
|
2229
|
+
n.ok && n.value.close();
|
|
2230
|
+
return;
|
|
2231
|
+
}
|
|
2232
|
+
if (!n.ok) {
|
|
2233
|
+
if (l(this, te, n.error), !Ko(n.error)) {
|
|
2234
|
+
a(this, v, yt).call(this), y("the app connection was rejected", {
|
|
2235
|
+
side: "app",
|
|
2236
|
+
attempt: r(this, be),
|
|
2237
|
+
retryable: !1,
|
|
2238
|
+
error: J(n.error)
|
|
2239
|
+
}), a(this, v, Ne).call(this, {
|
|
2240
|
+
state: "rejected",
|
|
2241
|
+
error: n.error
|
|
2242
|
+
});
|
|
2243
|
+
return;
|
|
2244
|
+
}
|
|
2245
|
+
a(this, v, Ne).call(this, r(this, z).state === "reconnecting" ? { state: "reconnecting", lastError: n.error } : { state: "connecting", error: n.error }), a(this, v, Kt).call(this);
|
|
2246
|
+
return;
|
|
2247
|
+
}
|
|
2248
|
+
l(this, de, n.value), l(this, te, void 0), r(this, ct).reset(), a(this, v, yt).call(this);
|
|
2249
|
+
let o = () => {
|
|
2250
|
+
r(this, ae).signal.aborted || r(this, de) !== n.value || (l(this, de, void 0), l(this, te, { code: "DISCONNECTED" }), x("the app lost its established connection", {
|
|
2251
|
+
side: "app",
|
|
2252
|
+
attempt: r(this, be),
|
|
2253
|
+
surfaceId: n.value.surfaceId
|
|
2254
|
+
}), a(this, v, Xt).call(this), a(this, v, Ne).call(this, {
|
|
2255
|
+
state: "reconnecting",
|
|
2256
|
+
lastError: r(this, te)
|
|
2257
|
+
}), a(this, v, Kt).call(this));
|
|
2258
|
+
};
|
|
2259
|
+
if (n.value.closeSignal.addEventListener("abort", o, {
|
|
2260
|
+
once: !0
|
|
2261
|
+
}), n.value.closeSignal.aborted) {
|
|
2262
|
+
o();
|
|
2263
|
+
return;
|
|
2264
|
+
}
|
|
2265
|
+
a(this, v, Ne).call(this, {
|
|
2266
|
+
state: "connected",
|
|
2267
|
+
connection: n.value.connection,
|
|
2268
|
+
surfaceId: n.value.surfaceId
|
|
2269
|
+
});
|
|
2270
|
+
}, Kt = function() {
|
|
2271
|
+
if (r(this, ae).signal.aborted || r(this, ke) || r(this, ce) !== void 0)
|
|
2272
|
+
return;
|
|
2273
|
+
let e = r(this, ct).next();
|
|
2274
|
+
x("retrying the app connection", {
|
|
2275
|
+
side: "app",
|
|
2276
|
+
state: r(this, z).state,
|
|
2277
|
+
failedAttempts: r(this, be),
|
|
2278
|
+
retryInMs: e,
|
|
2279
|
+
giveUpAfterMs: et,
|
|
2280
|
+
error: r(this, te) && J(r(this, te))
|
|
2281
|
+
}), l(this, ce, globalThis.setTimeout(() => {
|
|
2282
|
+
l(this, ce, void 0), a(this, v, Jt).call(this);
|
|
2283
|
+
}, e));
|
|
2284
|
+
}, Zt = function() {
|
|
2285
|
+
r(this, ce) !== void 0 && (globalThis.clearTimeout(r(this, ce)), l(this, ce, void 0));
|
|
2286
|
+
}, Xt = function() {
|
|
2287
|
+
r(this, le) === void 0 && l(this, le, globalThis.setTimeout(() => {
|
|
2288
|
+
l(this, le, void 0), a(this, v, qn).call(this);
|
|
2289
|
+
}, et));
|
|
2290
|
+
}, yt = function() {
|
|
2291
|
+
r(this, le) !== void 0 && (globalThis.clearTimeout(r(this, le)), l(this, le, void 0));
|
|
2292
|
+
}, qn = function() {
|
|
2293
|
+
if (r(this, ae).signal.aborted || r(this, z).state === "connected" || r(this, z).state === "closed")
|
|
2294
|
+
return;
|
|
2295
|
+
l(this, ke, !0), a(this, v, Zt).call(this), r(this, ee)?.abort(), l(this, ee, void 0);
|
|
2296
|
+
let e = r(this, te) ?? {
|
|
2297
|
+
code: "TIMED_OUT",
|
|
2298
|
+
timeoutMs: et
|
|
2299
|
+
};
|
|
2300
|
+
y("the app gave up connecting to its Datadog host", {
|
|
2301
|
+
side: "app",
|
|
2302
|
+
state: r(this, z).state,
|
|
2303
|
+
failedAttempts: r(this, be),
|
|
2304
|
+
gaveUpAfterMs: et,
|
|
2305
|
+
error: J(e)
|
|
2306
|
+
}), a(this, v, Ne).call(this, { state: "rejected", error: e });
|
|
2307
|
+
}, Ne = function(e) {
|
|
2308
|
+
r(this, z) !== e && (l(this, z, e), ge(r(this, Se)));
|
|
2309
|
+
};
|
|
2310
|
+
var eo = /* @__PURE__ */ Object.freeze({
|
|
2311
|
+
connect() {
|
|
2312
|
+
return new Gt();
|
|
2313
|
+
}
|
|
2314
|
+
});
|
|
2315
|
+
|
|
2316
|
+
// src/embedding/errors.ts
|
|
2317
|
+
function to(t) {
|
|
2318
|
+
return t.join(", ");
|
|
2319
|
+
}
|
|
2320
|
+
function Zo(t) {
|
|
2321
|
+
return t.map(
|
|
2322
|
+
(e) => `${e.path.length > 0 ? e.path.join(".") : "(root)"}: ${e.message}`
|
|
2323
|
+
).join("; ");
|
|
2324
|
+
}
|
|
2325
|
+
function Xo(t) {
|
|
2326
|
+
let e;
|
|
2327
|
+
try {
|
|
2328
|
+
if (t instanceof Error)
|
|
2329
|
+
e = t.message || t.name;
|
|
2330
|
+
else if (typeof t == "string")
|
|
2331
|
+
e = t;
|
|
2332
|
+
else
|
|
2333
|
+
try {
|
|
2334
|
+
e = JSON.stringify(t) ?? String(t);
|
|
2335
|
+
} catch {
|
|
2336
|
+
e = Object.prototype.toString.call(t);
|
|
2337
|
+
}
|
|
2338
|
+
} catch {
|
|
2339
|
+
e = "(cause could not be described)";
|
|
2340
|
+
}
|
|
2341
|
+
return e.length > 200 ? `${e.slice(0, 200)}\u2026` : e;
|
|
2342
|
+
}
|
|
2343
|
+
function Yt(t) {
|
|
2344
|
+
switch (t.code) {
|
|
2345
|
+
case "TIMED_OUT":
|
|
2346
|
+
return {
|
|
2347
|
+
code: "TIMED_OUT",
|
|
2348
|
+
action: "retry",
|
|
2349
|
+
message: `TIMED_OUT: the Datadog host did not complete the connection within ${t.timeoutMs}ms. Reload the app to try again.`
|
|
2350
|
+
};
|
|
2351
|
+
case "ORIGIN_REJECTED":
|
|
2352
|
+
return {
|
|
2353
|
+
code: "ORIGIN_REJECTED",
|
|
2354
|
+
action: "contact-support",
|
|
2355
|
+
message: `ORIGIN_REJECTED: the embedding connection failed origin validation for "${t.origin}". Screenshot this message and contact support.`
|
|
2356
|
+
};
|
|
2357
|
+
case "APP_PROTOCOL_TOO_OLD":
|
|
2358
|
+
return {
|
|
2359
|
+
code: "APP_PROTOCOL_TOO_OLD",
|
|
2360
|
+
action: "update-app",
|
|
2361
|
+
message: `APP_PROTOCOL_TOO_OLD: this app supports embedding protocols ${t.appProtocols.join(", ")}, while the Datadog host requires ${t.hostProtocols.join(", ")}. Update @datadog/apps-frontend, rebuild this app, and upload the new bundle.`
|
|
2362
|
+
};
|
|
2363
|
+
case "HOST_PROTOCOL_TOO_OLD":
|
|
2364
|
+
return {
|
|
2365
|
+
code: "HOST_PROTOCOL_TOO_OLD",
|
|
2366
|
+
action: "contact-support",
|
|
2367
|
+
message: `HOST_PROTOCOL_TOO_OLD: this app supports embedding protocols ${t.appProtocols.join(", ")}, newer than the Datadog host's ${t.hostProtocols.join(", ")}. Rebuilding the app will not fix this; screenshot this message and contact support.`
|
|
2368
|
+
};
|
|
2369
|
+
case "PROTOCOL_INCOMPATIBLE":
|
|
2370
|
+
return {
|
|
2371
|
+
code: "PROTOCOL_INCOMPATIBLE",
|
|
2372
|
+
action: "contact-support",
|
|
2373
|
+
message: `PROTOCOL_INCOMPATIBLE: this app supports embedding protocols ${t.appProtocols.join(", ")}, while the Datadog host supports ${t.hostProtocols.join(", ")}. The sets do not overlap; screenshot this message and contact support.`
|
|
2374
|
+
};
|
|
2375
|
+
case "DISCONNECTED":
|
|
2376
|
+
return {
|
|
2377
|
+
code: "CONNECTION_LOST",
|
|
2378
|
+
action: "retry",
|
|
2379
|
+
message: "CONNECTION_LOST: the Datadog host stopped responding and the connection could not be re-established. Reload the app to try again."
|
|
2380
|
+
};
|
|
2381
|
+
case "TRANSPORT_FAILED":
|
|
2382
|
+
return {
|
|
2383
|
+
code: "UNKNOWN",
|
|
2384
|
+
action: "contact-support",
|
|
2385
|
+
message: `TRANSPORT_FAILED: the local embedding transport failed (${Xo(t.cause)}). Screenshot this message and contact support.`
|
|
2386
|
+
};
|
|
2387
|
+
case "UNRECOGNIZED":
|
|
2388
|
+
return {
|
|
2389
|
+
code: "UNKNOWN",
|
|
2390
|
+
action: "contact-support",
|
|
2391
|
+
message: `UNRECOGNIZED: the peer reported failure code "${t.rawCode}", which this app build does not know. Screenshot this message and contact support.`
|
|
2392
|
+
};
|
|
2393
|
+
case "ABORTED":
|
|
2394
|
+
return {
|
|
2395
|
+
code: "UNKNOWN",
|
|
2396
|
+
action: "contact-support",
|
|
2397
|
+
message: "ABORTED: the embedding connection was cancelled unexpectedly. Screenshot this message and contact support."
|
|
2398
|
+
};
|
|
2399
|
+
default:
|
|
2400
|
+
return t;
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
function Qt(t) {
|
|
2404
|
+
switch (t.code) {
|
|
2405
|
+
case "APP_MAJOR_TOO_OLD":
|
|
2406
|
+
return {
|
|
2407
|
+
code: "APP_MAJOR_TOO_OLD",
|
|
2408
|
+
action: "update-app",
|
|
2409
|
+
requestedVersion: t.wanted,
|
|
2410
|
+
availableVersions: t.hostVersions,
|
|
2411
|
+
message: `APP_MAJOR_TOO_OLD: this app's claim requests v${t.wanted}, while the host now offers ${to(t.hostVersions)}. Update @datadog/apps-frontend, rebuild this app, and upload the new bundle.`
|
|
2412
|
+
};
|
|
2413
|
+
case "HOST_MAJOR_TOO_OLD":
|
|
2414
|
+
return {
|
|
2415
|
+
code: "HOST_MAJOR_TOO_OLD",
|
|
2416
|
+
action: "contact-support",
|
|
2417
|
+
requestedVersion: t.wanted,
|
|
2418
|
+
availableVersions: t.hostVersions,
|
|
2419
|
+
message: `HOST_MAJOR_TOO_OLD: this app's claim requests v${t.wanted}, newer than the host's ${to(t.hostVersions)}. Rebuilding the app will not fix this; screenshot this message and contact support.`
|
|
2420
|
+
};
|
|
2421
|
+
case "CONTRACT_INCOMPATIBLE":
|
|
2422
|
+
return {
|
|
2423
|
+
code: "UNKNOWN",
|
|
2424
|
+
action: "contact-support",
|
|
2425
|
+
message: `CONTRACT_INCOMPATIBLE: the host omitted required field "${t.field}" despite advertising a compatible contract version. Screenshot this message and contact support.`
|
|
2426
|
+
};
|
|
2427
|
+
case "INVALID_RESULT":
|
|
2428
|
+
return {
|
|
2429
|
+
code: "UNKNOWN",
|
|
2430
|
+
action: "contact-support",
|
|
2431
|
+
message: `INVALID_RESULT: a host value failed this app's bundled parser (${Zo(t.issues)}). Screenshot this message and contact support.`
|
|
2432
|
+
};
|
|
2433
|
+
case "TIMED_OUT":
|
|
2434
|
+
return {
|
|
2435
|
+
code: "TIMED_OUT",
|
|
2436
|
+
action: "retry",
|
|
2437
|
+
message: `TIMED_OUT: the Datadog host did not complete the claim request within ${t.timeoutMs}ms. Reload the app to try again.`
|
|
2438
|
+
};
|
|
2439
|
+
case "DISCONNECTED":
|
|
2440
|
+
case "UNRECOGNIZED":
|
|
2441
|
+
return Yt(t);
|
|
2442
|
+
default:
|
|
2443
|
+
return t;
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
// src/embedding/runtime.ts
|
|
2448
|
+
var Yo = 0, Qo = Object.freeze({
|
|
2449
|
+
status: "pending"
|
|
2450
|
+
}), qo = Object.freeze({
|
|
2451
|
+
status: "unavailable"
|
|
2452
|
+
}), er = Object.freeze({
|
|
2453
|
+
code: "UNKNOWN",
|
|
2454
|
+
action: "contact-support",
|
|
2455
|
+
message: "EMBEDDING_CLOSED: the Datadog App connection closed while its provider was still mounted. Screenshot this message and contact support."
|
|
2456
|
+
}), qt = Object.freeze({
|
|
2457
|
+
code: "UNKNOWN",
|
|
2458
|
+
action: "contact-support",
|
|
2459
|
+
message: "CLAIM_REJECTED: the requested Datadog App claim failed unexpectedly. Screenshot this message and contact support."
|
|
2460
|
+
}), no = Object.freeze({
|
|
2461
|
+
code: "UNKNOWN",
|
|
2462
|
+
action: "contact-support",
|
|
2463
|
+
message: "CONNECTION_START_FAILED: the Datadog App connection could not be started. Screenshot this message and contact support."
|
|
2464
|
+
});
|
|
2465
|
+
function en() {
|
|
2466
|
+
return Qo;
|
|
2467
|
+
}
|
|
2468
|
+
function oo() {
|
|
2469
|
+
return qo;
|
|
2470
|
+
}
|
|
2471
|
+
function tr(t) {
|
|
2472
|
+
let e = "requestedVersion" in t ? Object.freeze({
|
|
2473
|
+
...t,
|
|
2474
|
+
availableVersions: Object.freeze([
|
|
2475
|
+
...t.availableVersions
|
|
2476
|
+
])
|
|
2477
|
+
}) : Object.freeze({ ...t });
|
|
2478
|
+
return Object.freeze({
|
|
2479
|
+
status: "failed",
|
|
2480
|
+
error: e
|
|
2481
|
+
});
|
|
2482
|
+
}
|
|
2483
|
+
var Re, pe, ve, vt = class {
|
|
2484
|
+
constructor(e, n) {
|
|
2485
|
+
this.owner = e;
|
|
2486
|
+
this.resource = n;
|
|
2487
|
+
p(this, Re, /* @__PURE__ */ new Set());
|
|
2488
|
+
p(this, pe);
|
|
2489
|
+
p(this, ve, !1);
|
|
2490
|
+
Fe(this, "subscribe", (e) => {
|
|
2491
|
+
r(this, pe) !== void 0 && (globalThis.clearTimeout(r(this, pe)), l(this, pe, void 0));
|
|
2492
|
+
let n = () => e();
|
|
2493
|
+
r(this, Re).add(n), r(this, ve) || (l(this, ve, !0), this.owner.activate(this.resource));
|
|
2494
|
+
let o = !0;
|
|
2495
|
+
return () => {
|
|
2496
|
+
o && (o = !1, r(this, Re).delete(n), r(this, Re).size === 0 && r(this, pe) === void 0 && l(this, pe, globalThis.setTimeout(() => {
|
|
2497
|
+
l(this, pe, void 0), r(this, Re).size === 0 && r(this, ve) && (l(this, ve, !1), this.owner.deactivate(this.resource));
|
|
2498
|
+
}, Yo)));
|
|
2499
|
+
};
|
|
2500
|
+
});
|
|
2501
|
+
}
|
|
2502
|
+
owner;
|
|
2503
|
+
resource;
|
|
2504
|
+
notify() {
|
|
2505
|
+
ge(r(this, Re));
|
|
2506
|
+
}
|
|
2507
|
+
get isActive() {
|
|
2508
|
+
return r(this, ve);
|
|
2509
|
+
}
|
|
2510
|
+
};
|
|
2511
|
+
Re = new WeakMap(), pe = new WeakMap(), ve = new WeakMap();
|
|
2512
|
+
var Ae, $, Ie, G, ne, he, Je, E, ro, io, so, on, Ge, ye, ue, Ue, nn = class {
|
|
2513
|
+
constructor(e, n) {
|
|
2514
|
+
p(this, E);
|
|
2515
|
+
p(this, Ae);
|
|
2516
|
+
p(this, $);
|
|
2517
|
+
p(this, Ie, en());
|
|
2518
|
+
p(this, G);
|
|
2519
|
+
p(this, ne);
|
|
2520
|
+
p(this, he);
|
|
2521
|
+
p(this, Je, []);
|
|
2522
|
+
Fe(this, "getSnapshot", () => r(this, Ie));
|
|
2523
|
+
Fe(this, "subscribe", (e) => r(this, Ae).subscribe(e));
|
|
2524
|
+
l(this, $, n), l(this, Ae, new vt(e, this));
|
|
2525
|
+
}
|
|
2526
|
+
sync(e) {
|
|
2527
|
+
if (!e) {
|
|
2528
|
+
this.reset();
|
|
2529
|
+
return;
|
|
2530
|
+
}
|
|
2531
|
+
switch (e.state) {
|
|
2532
|
+
case "connected":
|
|
2533
|
+
if (r(this, G) === e.connection)
|
|
2534
|
+
return;
|
|
2535
|
+
a(this, E, ye).call(this), l(this, G, e.connection), a(this, E, Ue).call(this, en()), a(this, E, ro).call(this, e.connection);
|
|
2536
|
+
return;
|
|
2537
|
+
case "connecting":
|
|
2538
|
+
case "reconnecting":
|
|
2539
|
+
this.reset();
|
|
2540
|
+
return;
|
|
2541
|
+
case "not-embedded":
|
|
2542
|
+
l(this, G, void 0), a(this, E, ye).call(this), a(this, E, Ue).call(this, oo());
|
|
2543
|
+
return;
|
|
2544
|
+
case "rejected":
|
|
2545
|
+
l(this, G, void 0), a(this, E, ye).call(this), a(this, E, ue).call(this, Yt(e.error));
|
|
2546
|
+
return;
|
|
2547
|
+
case "closed":
|
|
2548
|
+
l(this, G, void 0), a(this, E, ye).call(this), a(this, E, ue).call(this, er);
|
|
2549
|
+
return;
|
|
2550
|
+
default:
|
|
2551
|
+
return e;
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
fail(e) {
|
|
2555
|
+
l(this, G, void 0), a(this, E, ye).call(this), a(this, E, ue).call(this, e);
|
|
2556
|
+
}
|
|
2557
|
+
reset() {
|
|
2558
|
+
l(this, G, void 0), a(this, E, ye).call(this), a(this, E, Ue).call(this, en());
|
|
2559
|
+
}
|
|
2560
|
+
};
|
|
2561
|
+
Ae = new WeakMap(), $ = new WeakMap(), Ie = new WeakMap(), G = new WeakMap(), ne = new WeakMap(), he = new WeakMap(), Je = new WeakMap(), E = new WeakSet(), ro = function(e) {
|
|
2562
|
+
let n = new AbortController();
|
|
2563
|
+
l(this, ne, n);
|
|
2564
|
+
let o;
|
|
2565
|
+
try {
|
|
2566
|
+
o = e.claim(r(this, $), {
|
|
2567
|
+
signal: n.signal
|
|
2568
|
+
});
|
|
2569
|
+
} catch (i) {
|
|
2570
|
+
y("a claim could not be requested", {
|
|
2571
|
+
side: "app",
|
|
2572
|
+
identifier: r(this, $).identifier,
|
|
2573
|
+
current: a(this, E, Ge).call(this, e, n),
|
|
2574
|
+
cause: S(i)
|
|
2575
|
+
}), a(this, E, Ge).call(this, e, n) && (l(this, ne, void 0), a(this, E, ue).call(this, qt));
|
|
2576
|
+
return;
|
|
2577
|
+
}
|
|
2578
|
+
o.then(
|
|
2579
|
+
(i) => {
|
|
2580
|
+
if (!a(this, E, Ge).call(this, e, n)) {
|
|
2581
|
+
i.ok && i.value.release();
|
|
2582
|
+
return;
|
|
2583
|
+
}
|
|
2584
|
+
if (l(this, ne, void 0), !i.ok) {
|
|
2585
|
+
if (i.error.code === "PEER_LACKS_MODULE") {
|
|
2586
|
+
x(
|
|
2587
|
+
"the Datadog host does not offer this module",
|
|
2588
|
+
{
|
|
2589
|
+
side: "app",
|
|
2590
|
+
identifier: r(this, $).identifier,
|
|
2591
|
+
version: r(this, $).version
|
|
2592
|
+
}
|
|
2593
|
+
), a(this, E, Ue).call(this, oo());
|
|
2594
|
+
return;
|
|
2595
|
+
}
|
|
2596
|
+
if (i.error.code === "ABORTED") {
|
|
2597
|
+
a(this, E, ue).call(this, qt);
|
|
2598
|
+
return;
|
|
2599
|
+
}
|
|
2600
|
+
a(this, E, ue).call(this, Qt(i.error));
|
|
2601
|
+
return;
|
|
2602
|
+
}
|
|
2603
|
+
a(this, E, io).call(this, e, i.value);
|
|
2604
|
+
},
|
|
2605
|
+
(i) => {
|
|
2606
|
+
y("a claim request rejected", {
|
|
2607
|
+
side: "app",
|
|
2608
|
+
identifier: r(this, $).identifier,
|
|
2609
|
+
current: a(this, E, Ge).call(this, e, n),
|
|
2610
|
+
cause: S(i)
|
|
2611
|
+
}), a(this, E, Ge).call(this, e, n) && (l(this, ne, void 0), a(this, E, ue).call(this, qt));
|
|
2612
|
+
}
|
|
2613
|
+
);
|
|
2614
|
+
}, io = function(e, n) {
|
|
2615
|
+
if (!r(this, Ae).isActive || r(this, G) !== e || r(this, he)) {
|
|
2616
|
+
n.release();
|
|
2617
|
+
return;
|
|
2618
|
+
}
|
|
2619
|
+
l(this, he, n), r(this, Je).push(
|
|
2620
|
+
n.onInvalidated(
|
|
2621
|
+
(o) => a(this, E, so).call(this, n, o)
|
|
2622
|
+
)
|
|
2623
|
+
), r(this, Je).push(
|
|
2624
|
+
n.onValuesChanged(() => {
|
|
2625
|
+
r(this, he) === n && a(this, E, on).call(this, n);
|
|
2626
|
+
})
|
|
2627
|
+
), a(this, E, on).call(this, n);
|
|
2628
|
+
}, so = function(e, n) {
|
|
2629
|
+
if (r(this, he) !== e)
|
|
2630
|
+
return;
|
|
2631
|
+
let o = Qt(n);
|
|
2632
|
+
a(this, E, ye).call(this), a(this, E, ue).call(this, o);
|
|
2633
|
+
}, on = function(e) {
|
|
2634
|
+
let n = Object.entries(r(this, $).fields), o = n.map(([s]) => s), i = /* @__PURE__ */ Object.create(null);
|
|
2635
|
+
for (let [s, d] of n) {
|
|
2636
|
+
let c = e.fields[s];
|
|
2637
|
+
i[s] = d.kind === "value" ? c.get() : c;
|
|
2638
|
+
}
|
|
2639
|
+
if (r(this, Ie).status === "ready") {
|
|
2640
|
+
let s = r(this, Ie).fields;
|
|
2641
|
+
if (o.every((d) => Object.is(s[d], i[d])))
|
|
2642
|
+
return;
|
|
2643
|
+
}
|
|
2644
|
+
a(this, E, Ue).call(this, Object.freeze({
|
|
2645
|
+
status: "ready",
|
|
2646
|
+
fields: Object.freeze(i)
|
|
2647
|
+
}));
|
|
2648
|
+
}, Ge = function(e, n) {
|
|
2649
|
+
return r(this, Ae).isActive && r(this, G) === e && r(this, ne) === n && !n.signal.aborted;
|
|
2650
|
+
}, ye = function() {
|
|
2651
|
+
r(this, ne)?.abort(), l(this, ne, void 0);
|
|
2652
|
+
for (let n of r(this, Je).splice(0))
|
|
2653
|
+
n();
|
|
2654
|
+
let e = r(this, he);
|
|
2655
|
+
l(this, he, void 0), e?.release();
|
|
2656
|
+
}, /**
|
|
2657
|
+
* The single place a claim becomes app-visibly failed. The public
|
|
2658
|
+
* `ClaimError` is what an app author can act on, and an app that renders a
|
|
2659
|
+
* fallback instead of reading `error` would otherwise leave no trace of
|
|
2660
|
+
* why its claim never delivered data.
|
|
2661
|
+
*/
|
|
2662
|
+
ue = function(e) {
|
|
2663
|
+
y("a Datadog App claim failed", {
|
|
2664
|
+
side: "app",
|
|
2665
|
+
identifier: r(this, $).identifier,
|
|
2666
|
+
version: r(this, $).version,
|
|
2667
|
+
code: e.code,
|
|
2668
|
+
action: e.action,
|
|
2669
|
+
reason: e.message
|
|
2670
|
+
}), a(this, E, Ue).call(this, tr(e));
|
|
2671
|
+
}, Ue = function(e) {
|
|
2672
|
+
r(this, Ie) !== e && (l(this, Ie, e), r(this, Ae).notify());
|
|
2673
|
+
};
|
|
2674
|
+
var tn = Object.freeze({
|
|
2675
|
+
state: "connecting"
|
|
2676
|
+
});
|
|
2677
|
+
function nr(t) {
|
|
2678
|
+
switch (t.state) {
|
|
2679
|
+
case "connecting":
|
|
2680
|
+
return { state: "connecting", error: t.error };
|
|
2681
|
+
case "connected":
|
|
2682
|
+
return { state: "connected", surfaceId: t.surfaceId };
|
|
2683
|
+
case "reconnecting":
|
|
2684
|
+
return { state: "reconnecting", lastError: t.lastError };
|
|
2685
|
+
case "rejected":
|
|
2686
|
+
return { state: "rejected", error: t.error };
|
|
2687
|
+
case "not-embedded":
|
|
2688
|
+
return { state: "not-embedded" };
|
|
2689
|
+
case "closed":
|
|
2690
|
+
return { state: "closed" };
|
|
2691
|
+
default:
|
|
2692
|
+
return t;
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
var Ke, Ze, Xe, Rt, rn = class {
|
|
2696
|
+
constructor(e) {
|
|
2697
|
+
p(this, Xe);
|
|
2698
|
+
p(this, Ke);
|
|
2699
|
+
p(this, Ze, tn);
|
|
2700
|
+
Fe(this, "getSnapshot", () => r(this, Ze));
|
|
2701
|
+
Fe(this, "subscribe", (e) => r(this, Ke).subscribe(e));
|
|
2702
|
+
l(this, Ke, new vt(e, this));
|
|
2703
|
+
}
|
|
2704
|
+
sync(e) {
|
|
2705
|
+
a(this, Xe, Rt).call(this, e ? nr(e) : tn);
|
|
2706
|
+
}
|
|
2707
|
+
fail(e) {
|
|
2708
|
+
a(this, Xe, Rt).call(this, {
|
|
2709
|
+
state: "rejected",
|
|
2710
|
+
error: { code: "TRANSPORT_FAILED", cause: e }
|
|
2711
|
+
});
|
|
2712
|
+
}
|
|
2713
|
+
reset() {
|
|
2714
|
+
a(this, Xe, Rt).call(this, tn);
|
|
2715
|
+
}
|
|
2716
|
+
};
|
|
2717
|
+
Ke = new WeakMap(), Ze = new WeakMap(), Xe = new WeakSet(), Rt = function(e) {
|
|
2718
|
+
r(this, Ze) !== e && (l(this, Ze, e), r(this, Ke).notify());
|
|
2719
|
+
};
|
|
2720
|
+
var lt, X, ut, fe, Ye, _e, Qe, Ve, L, ao, co, lo, uo, an, dn, cn, sn = class {
|
|
2721
|
+
constructor(e) {
|
|
2722
|
+
this.connector = e;
|
|
2723
|
+
p(this, L);
|
|
2724
|
+
p(this, lt, /* @__PURE__ */ new WeakMap());
|
|
2725
|
+
p(this, X, /* @__PURE__ */ new Set());
|
|
2726
|
+
p(this, ut, {
|
|
2727
|
+
activate: (e) => a(this, L, lo).call(this, e),
|
|
2728
|
+
deactivate: (e) => a(this, L, uo).call(this, e)
|
|
2729
|
+
});
|
|
2730
|
+
p(this, fe);
|
|
2731
|
+
p(this, Ye);
|
|
2732
|
+
p(this, _e);
|
|
2733
|
+
p(this, Qe);
|
|
2734
|
+
p(this, Ve, 0);
|
|
2735
|
+
}
|
|
2736
|
+
connector;
|
|
2737
|
+
getClaim(e) {
|
|
2738
|
+
let n = e, o = r(this, lt).get(n);
|
|
2739
|
+
if (o)
|
|
2740
|
+
return o;
|
|
2741
|
+
let i = new nn(
|
|
2742
|
+
r(this, ut),
|
|
2743
|
+
e
|
|
2744
|
+
);
|
|
2745
|
+
return r(this, lt).set(n, i), i;
|
|
2746
|
+
}
|
|
2747
|
+
getEmbeddingMetadata() {
|
|
2748
|
+
return r(this, Qe) || l(this, Qe, new rn(r(this, ut))), r(this, Qe);
|
|
2749
|
+
}
|
|
2750
|
+
start() {
|
|
2751
|
+
l(this, Ve, r(this, Ve) + 1), r(this, Ve) === 1 && a(this, L, ao).call(this);
|
|
2752
|
+
let e = !0;
|
|
2753
|
+
return () => {
|
|
2754
|
+
e && (e = !1, l(this, Ve, r(this, Ve) - 1), r(this, Ve) === 0 && a(this, L, co).call(this));
|
|
2755
|
+
};
|
|
2756
|
+
}
|
|
2757
|
+
};
|
|
2758
|
+
lt = new WeakMap(), X = new WeakMap(), ut = new WeakMap(), fe = new WeakMap(), Ye = new WeakMap(), _e = new WeakMap(), Qe = new WeakMap(), Ve = new WeakMap(), L = new WeakSet(), ao = function() {
|
|
2759
|
+
l(this, _e, void 0);
|
|
2760
|
+
for (let n of r(this, X))
|
|
2761
|
+
n.reset();
|
|
2762
|
+
let e;
|
|
2763
|
+
try {
|
|
2764
|
+
e = this.connector.connect();
|
|
2765
|
+
} catch (n) {
|
|
2766
|
+
a(this, L, cn).call(this, "connect", n);
|
|
2767
|
+
return;
|
|
2768
|
+
}
|
|
2769
|
+
l(this, fe, e);
|
|
2770
|
+
try {
|
|
2771
|
+
l(this, Ye, e.subscribe(
|
|
2772
|
+
() => a(this, L, an).call(this, e)
|
|
2773
|
+
)), a(this, L, an).call(this, e);
|
|
2774
|
+
} catch (n) {
|
|
2775
|
+
a(this, L, dn).call(this, e), a(this, L, cn).call(this, "subscribe", n);
|
|
2776
|
+
return;
|
|
2777
|
+
}
|
|
2778
|
+
}, co = function() {
|
|
2779
|
+
let e = r(this, fe);
|
|
2780
|
+
e && a(this, L, dn).call(this, e), l(this, _e, void 0);
|
|
2781
|
+
for (let n of r(this, X))
|
|
2782
|
+
n.reset();
|
|
2783
|
+
}, lo = function(e) {
|
|
2784
|
+
if (r(this, X).add(e), r(this, _e)) {
|
|
2785
|
+
e.fail(r(this, _e));
|
|
2786
|
+
return;
|
|
2787
|
+
}
|
|
2788
|
+
e.sync(r(this, fe)?.getSnapshot());
|
|
2789
|
+
}, uo = function(e) {
|
|
2790
|
+
r(this, X).delete(e), e.reset();
|
|
2791
|
+
}, an = function(e) {
|
|
2792
|
+
if (r(this, fe) !== e)
|
|
2793
|
+
return;
|
|
2794
|
+
let n = e.getSnapshot();
|
|
2795
|
+
for (let o of r(this, X))
|
|
2796
|
+
o.sync(n);
|
|
2797
|
+
}, dn = function(e) {
|
|
2798
|
+
if (r(this, fe) !== e)
|
|
2799
|
+
return;
|
|
2800
|
+
l(this, fe, void 0);
|
|
2801
|
+
let n = r(this, Ye);
|
|
2802
|
+
l(this, Ye, void 0), n && w(
|
|
2803
|
+
"embedding connection handle unsubscribe",
|
|
2804
|
+
() => n()
|
|
2805
|
+
);
|
|
2806
|
+
for (let o of r(this, X))
|
|
2807
|
+
w("embedding claim resource reset", () => o.reset());
|
|
2808
|
+
w("embedding connection handle close", () => e.close());
|
|
2809
|
+
}, // The connector itself threw, which no `ConnectError` describes: nothing
|
|
2810
|
+
// downstream ever sees this cause, so it is reported where it is caught.
|
|
2811
|
+
cn = function(e, n) {
|
|
2812
|
+
y("the embedding connection could not be started", {
|
|
2813
|
+
side: "app",
|
|
2814
|
+
step: e,
|
|
2815
|
+
affectedResources: r(this, X).size,
|
|
2816
|
+
cause: S(n)
|
|
2817
|
+
}), l(this, _e, no);
|
|
2818
|
+
for (let o of r(this, X))
|
|
2819
|
+
o.fail(no);
|
|
2820
|
+
};
|
|
2821
|
+
function po(t) {
|
|
2822
|
+
return new sn(t);
|
|
2823
|
+
}
|
|
2824
|
+
|
|
2825
|
+
// src/embedding/react/provider.ts
|
|
2826
|
+
var ho = po(eo), sr = In(ho), ar = Object.freeze([Rn()]);
|
|
2827
|
+
function dr(t) {
|
|
2828
|
+
try {
|
|
2829
|
+
console.warn(t);
|
|
2830
|
+
} catch {
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
function cr(t, e, n) {
|
|
2834
|
+
let o = e ?? [], i = new Set(o.map((c) => c.id)), s = new Set(n ?? []), d = t.filter(
|
|
2835
|
+
(c) => !s.has(c.id) && !i.has(c.id)
|
|
2836
|
+
);
|
|
2837
|
+
if (s.size === 0)
|
|
2838
|
+
return [...d, ...o];
|
|
2839
|
+
for (let c of o)
|
|
2840
|
+
if (s.has(c.id))
|
|
2841
|
+
throw new Error(
|
|
2842
|
+
`DatadogAppProvider received module "${c.id}" in both modules and disabledModules.`
|
|
2843
|
+
);
|
|
2844
|
+
for (let c of s)
|
|
2845
|
+
t.some((f) => f.id === c) || o.some((f) => f.id === c) || dr(
|
|
2846
|
+
`[Datadog App provider] disabledModules names "${c}", but no module with that id is installed.`
|
|
2847
|
+
);
|
|
2848
|
+
return [...d, ...o];
|
|
2849
|
+
}
|
|
2850
|
+
var lr = ({
|
|
2851
|
+
children: t,
|
|
2852
|
+
modules: e,
|
|
2853
|
+
disabledModules: n
|
|
2854
|
+
}) => {
|
|
2855
|
+
let [o] = ir(
|
|
2856
|
+
() => cr(
|
|
2857
|
+
ar,
|
|
2858
|
+
e,
|
|
2859
|
+
n
|
|
2860
|
+
)
|
|
2861
|
+
);
|
|
2862
|
+
return rr(() => {
|
|
2863
|
+
let i = new AbortController();
|
|
2864
|
+
return gn(
|
|
2865
|
+
o,
|
|
2866
|
+
ho,
|
|
2867
|
+
i.signal
|
|
2868
|
+
), () => i.abort();
|
|
2869
|
+
}, [o]), or(sr, null, t);
|
|
2870
|
+
};
|
|
2871
|
+
|
|
2872
|
+
// src/embedding/react/use-datadog-app-embedding.ts
|
|
2873
|
+
import { useSyncExternalStore as ur } from "react";
|
|
2874
|
+
var ln = /* @__PURE__ */ new WeakMap();
|
|
2875
|
+
function fo(t) {
|
|
2876
|
+
return t === "connecting" || t === "reconnecting";
|
|
2877
|
+
}
|
|
2878
|
+
function pr(t, e) {
|
|
2879
|
+
let n = ln.get(e);
|
|
2880
|
+
if (!n) {
|
|
2881
|
+
let o = vn(t), i;
|
|
2882
|
+
n = new Promise((h) => {
|
|
2883
|
+
i = h;
|
|
2884
|
+
}), ln.set(e, n);
|
|
2885
|
+
let s, d = !1, c = () => {
|
|
2886
|
+
d || fo(e.getSnapshot().state) || (d = !0, s?.(), ln.delete(e), An(t, o), i());
|
|
2887
|
+
};
|
|
2888
|
+
s = e.subscribe(c), d ? s() : c();
|
|
2889
|
+
}
|
|
2890
|
+
throw n;
|
|
2891
|
+
}
|
|
2892
|
+
function hr() {
|
|
2893
|
+
throw new Error(
|
|
2894
|
+
"useDatadogAppEmbedding does not support server rendering: the Datadog App embedding connection only exists in the browser."
|
|
2895
|
+
);
|
|
2896
|
+
}
|
|
2897
|
+
function fr(t) {
|
|
2898
|
+
throw new Error(
|
|
2899
|
+
t.state === "rejected" ? `The Datadog App embedding connection was rejected: ${t.error.code}.` : "The Datadog App embedding connection closed."
|
|
2900
|
+
);
|
|
2901
|
+
}
|
|
2902
|
+
function mr(t) {
|
|
2903
|
+
let e = _n(), n = e.getEmbeddingMetadata(), o = ur(
|
|
2904
|
+
n.subscribe,
|
|
2905
|
+
n.getSnapshot,
|
|
2906
|
+
hr
|
|
2907
|
+
);
|
|
2908
|
+
return t?.suspense && (fo(o.state) && pr(e, n), (o.state === "rejected" || o.state === "closed") && fr(o)), o;
|
|
2909
|
+
}
|
|
2910
|
+
export {
|
|
2911
|
+
lr as DatadogAppProvider,
|
|
2912
|
+
mr as useDatadogAppEmbedding
|
|
2913
|
+
};
|
|
7
2914
|
//# sourceMappingURL=index.js.map
|