@datadog/apps-frontend 0.0.7 → 0.0.9
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/README.md +7 -0
- package/dist/src/_chunks/{chunk-2ZECSTB4.js → chunk-D43RPVCF.js} +2 -2
- package/dist/src/_chunks/chunk-DETZPDFA.js +7 -0
- package/dist/src/_chunks/chunk-DETZPDFA.js.map +7 -0
- package/dist/src/_chunks/chunk-EYBITW7J.js +7 -0
- package/dist/src/_chunks/chunk-EYBITW7J.js.map +7 -0
- package/dist/src/_chunks/chunk-OEPH347K.js +7 -0
- package/dist/src/_chunks/{chunk-G2SXTUX4.js.map → chunk-OEPH347K.js.map} +3 -3
- package/dist/src/_chunks/{chunk-627KNBXP.js → chunk-XSHCFEOH.js} +2 -2
- package/dist/src/_chunks/chunk-XSHCFEOH.js.map +7 -0
- package/dist/src/deep-links/react/index.js +1 -1
- package/dist/src/druids/react/index.js +1 -1
- package/dist/src/embedding/react/index.js +1 -1
- package/dist/src/inputs/published-definition.d.ts +39 -8
- package/dist/src/inputs/react/index.js +1 -1
- package/dist/src/inputs/schemas/generated/consumers/dashboard.d.ts +35 -0
- package/dist/src/inputs/schemas/generated/consumers/index.d.ts +15 -0
- package/dist/src/inputs/schemas/generated/consumers/notebook.d.ts +36 -0
- package/dist/src/inputs/schemas/generated/consumers/service-panel.d.ts +15 -0
- package/dist/src/inputs/schemas/generated/consumers/theme.d.ts +15 -0
- package/dist/src/inputs/schemas/index.d.ts +1 -20
- package/dist/src/inputs/schemas/index.js +1 -1
- package/dist/src/inputs/types.d.ts +19 -7
- package/package.json +5 -2
- package/dist/src/_chunks/chunk-627KNBXP.js.map +0 -7
- package/dist/src/_chunks/chunk-G2SXTUX4.js +0 -7
- package/dist/src/_chunks/chunk-PA4Z7DNH.js +0 -7
- package/dist/src/_chunks/chunk-PA4Z7DNH.js.map +0 -7
- package/dist/src/_chunks/chunk-QOXXZE7D.js +0 -7
- package/dist/src/_chunks/chunk-QOXXZE7D.js.map +0 -7
- package/dist/src/inputs/schemas/dashboard.d.ts +0 -30
- package/dist/src/inputs/schemas/theme.d.ts +0 -15
- /package/dist/src/_chunks/{chunk-2ZECSTB4.js.map → chunk-D43RPVCF.js.map} +0 -0
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* Copyright 2019-Present Datadog, Inc.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import{a as gn,b as Rn}from"../../_chunks/chunk-2ZECSTB4.js";import{a as vn,b as An,c as In,d as _n}from"../../_chunks/chunk-2V2HASKF.js";import"../../_chunks/chunk-PA4Z7DNH.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{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};
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -30,13 +30,33 @@ export type PublishedDatadogAppInputsDefinition<TSchema extends AnyDatadogAppInp
|
|
|
30
30
|
export type AnyPublishedDatadogAppInputsDefinition = AnyDatadogAppInputsSchema & Readonly<{
|
|
31
31
|
[publishedDefinitionBrand]: unknown;
|
|
32
32
|
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Selected-public-version descriptor. Its exported object/API and declaration
|
|
35
|
+
* omit host construction and retained-version operations; this is not a
|
|
36
|
+
* transitive-source or bundle-secrecy boundary.
|
|
37
|
+
*/
|
|
38
|
+
export type PublishedDatadogAppInput<TCurrent extends AnyContract, TSurfaces extends readonly SurfaceId[] = typeof EVERY_SURFACE> = Readonly<{
|
|
39
|
+
identifier: TCurrent['identifier'];
|
|
40
|
+
latest: TCurrent;
|
|
41
|
+
fields: TCurrent['fields'];
|
|
42
|
+
surfaces: TSurfaces;
|
|
43
|
+
[publishedDefinitionBrand]: (fields: TCurrent['fields']) => TCurrent['fields'];
|
|
44
|
+
}>;
|
|
45
|
+
/** The common claimable shape shared by package-owned host and consumer definitions. */
|
|
46
|
+
export type AnyPublishedDatadogAppInput = Readonly<{
|
|
47
|
+
identifier: string;
|
|
48
|
+
latest: AnyContract;
|
|
49
|
+
fields: Readonly<Record<string, AnyField>>;
|
|
50
|
+
surfaces: readonly SurfaceId[];
|
|
51
|
+
[publishedDefinitionBrand]: unknown;
|
|
52
|
+
}>;
|
|
33
53
|
type PortableSchema<TSchema extends AnySchema> = ValueSchema<InferOf<TSchema>>;
|
|
34
54
|
interface PortableValueBuilder {
|
|
35
55
|
readOnly<TSchema extends AnySchema>(schema: ValidationOnlySchema<TSchema>): ValueField<PortableSchema<TSchema>>;
|
|
36
56
|
}
|
|
37
57
|
interface PortableFunctionBuilder {
|
|
38
58
|
readOnly<const TInputs extends Readonly<Record<string, AnySchema>>, TResult extends AnySchema>(definition: Readonly<{
|
|
39
|
-
inputs: {
|
|
59
|
+
inputs: TInputs & {
|
|
40
60
|
readonly [TName in keyof TInputs]: ValidationOnlySchema<TInputs[TName]>;
|
|
41
61
|
};
|
|
42
62
|
result: ValidationOnlySchema<TResult>;
|
|
@@ -82,7 +102,8 @@ export declare function datadogAppInputsVersion<const TIdentifier extends string
|
|
|
82
102
|
fields: ValidationOnlyFields<TFields>;
|
|
83
103
|
}>): PortableContract<TIdentifier, TVersion, TFields>;
|
|
84
104
|
/**
|
|
85
|
-
*
|
|
105
|
+
* Builds one package-owned versioned host definition. Schema publication
|
|
106
|
+
* separately chooses which served version the public SDK descriptor exposes.
|
|
86
107
|
*
|
|
87
108
|
* The common case is one version, declared inline -- `identifier`, `version`,
|
|
88
109
|
* `fields`, and optionally the `surfaces` it is offered on. A schema that has
|
|
@@ -106,15 +127,25 @@ export declare function datadogAppInputsDefinition<TLatest extends AnyContract,
|
|
|
106
127
|
surfaces?: TSurfaces;
|
|
107
128
|
olderVersions?: TOlderVersions;
|
|
108
129
|
}>): PublishedDatadogAppInputsDefinition<DatadogAppInputsSchema<TLatest, TSurfaces, TOlderVersions>>;
|
|
130
|
+
type ServedContract<TDefinition extends AnyPublishedDatadogAppInputsDefinition> = TDefinition['latest'] | Extract<TDefinition['olderVersions'][number], {
|
|
131
|
+
readonly contract: AnyContract;
|
|
132
|
+
}>['contract'];
|
|
133
|
+
/**
|
|
134
|
+
* Creates a selected-public-version descriptor for a contract the host serves.
|
|
135
|
+
* The boundary is its exported object/API and declaration, not transitive
|
|
136
|
+
* source dependencies or bundle secrecy.
|
|
137
|
+
*/
|
|
138
|
+
export declare function createDatadogAppInputConsumer<TDefinition extends AnyPublishedDatadogAppInputsDefinition>(definition: TDefinition): PublishedDatadogAppInput<TDefinition['latest'], TDefinition['surfaces']>;
|
|
139
|
+
export declare function createDatadogAppInputConsumer<TDefinition extends AnyPublishedDatadogAppInputsDefinition, TContract extends ServedContract<TDefinition>>(definition: TDefinition, contract: TContract): PublishedDatadogAppInput<TContract, TDefinition['surfaces']>;
|
|
109
140
|
/** Rejects copied or user-authored definitions at the public React boundary. */
|
|
110
|
-
export declare function assertPublishedDatadogAppInputsDefinition(definition: unknown): asserts definition is
|
|
141
|
+
export declare function assertPublishedDatadogAppInputsDefinition(definition: unknown): asserts definition is AnyPublishedDatadogAppInput;
|
|
111
142
|
/**
|
|
112
|
-
* Reports whether a value is a definition
|
|
113
|
-
*
|
|
114
|
-
* same `WeakSet`
|
|
115
|
-
*
|
|
143
|
+
* Reports whether a value is a package-created host definition or consumer
|
|
144
|
+
* descriptor. This ownership brand does not decide public SDK publication or
|
|
145
|
+
* authorization. It uses the same `WeakSet` as
|
|
146
|
+
* `assertPublishedDatadogAppInputsDefinition`, so a copied lookalike does not match.
|
|
116
147
|
*/
|
|
117
|
-
export declare function isPublishedDatadogAppInputsDefinition(definition: unknown): definition is
|
|
148
|
+
export declare function isPublishedDatadogAppInputsDefinition(definition: unknown): definition is AnyPublishedDatadogAppInput;
|
|
118
149
|
/**
|
|
119
150
|
* Turns one plain value into the field descriptor that carries it: a function
|
|
120
151
|
* becomes a callable field with validated inputs and result, anything else a
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* Copyright 2019-Present Datadog, Inc.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import{a}from"../../_chunks/chunk-
|
|
6
|
+
import{a}from"../../_chunks/chunk-XSHCFEOH.js";import"../../_chunks/chunk-2V2HASKF.js";import"../../_chunks/chunk-OEPH347K.js";import"../../_chunks/chunk-LEEYMNMO.js";export{a as useDatadogAppInput};
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0.
|
|
2
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
3
|
+
* Copyright 2019-Present Datadog, Inc.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ValueSchema, ValueField } from '../../../../embedding/types.js';
|
|
7
|
+
import type { PortableContract, PublishedDatadogAppInput } from '../../../published-definition.js';
|
|
8
|
+
import type { DatadogAppInputsHostValues } from '../../../types.js';
|
|
9
|
+
type Payload0 = {
|
|
10
|
+
"timeframe": Payload1;
|
|
11
|
+
"templateVariables": Payload3;
|
|
12
|
+
};
|
|
13
|
+
type Payload1 = {
|
|
14
|
+
"start": number;
|
|
15
|
+
"end": number;
|
|
16
|
+
"isLive": Payload2;
|
|
17
|
+
};
|
|
18
|
+
type Payload2 = false | true;
|
|
19
|
+
type Payload3 = Array<Payload4>;
|
|
20
|
+
type Payload4 = {
|
|
21
|
+
"name": string;
|
|
22
|
+
"value": string;
|
|
23
|
+
"values"?: Payload5;
|
|
24
|
+
"prefix"?: Payload7;
|
|
25
|
+
"default"?: Payload7;
|
|
26
|
+
};
|
|
27
|
+
type Payload5 = undefined | Payload6;
|
|
28
|
+
type Payload6 = Array<string>;
|
|
29
|
+
type Payload7 = undefined | string;
|
|
30
|
+
type Current = PortableContract<"datadog.dashboard", 1, {
|
|
31
|
+
"dashboard": ValueField<ValueSchema<Payload0>>;
|
|
32
|
+
}>;
|
|
33
|
+
export declare const datadogDashboard: PublishedDatadogAppInput<Current, readonly ["datadog.dashboard"]>;
|
|
34
|
+
export type DashboardInputs = DatadogAppInputsHostValues<typeof datadogDashboard>;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0.
|
|
2
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
3
|
+
* Copyright 2019-Present Datadog, Inc.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { AnyPublishedDatadogAppInput } from '../../../published-definition.js';
|
|
7
|
+
export { datadogTheme } from './theme.js';
|
|
8
|
+
export type { DatadogAppTheme } from './theme.js';
|
|
9
|
+
export { datadogDashboard } from './dashboard.js';
|
|
10
|
+
export type { DashboardInputs } from './dashboard.js';
|
|
11
|
+
export { datadogNotebook } from './notebook.js';
|
|
12
|
+
export type { NotebookInputs } from './notebook.js';
|
|
13
|
+
export { datadogServicePanel } from './service-panel.js';
|
|
14
|
+
export type { ServicePanelInputs } from './service-panel.js';
|
|
15
|
+
export type DatadogAppInputDefinition = Extract<(typeof import('./index.js'))[keyof typeof import('./index.js')], AnyPublishedDatadogAppInput>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0.
|
|
2
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
3
|
+
* Copyright 2019-Present Datadog, Inc.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ValueSchema, ValueField } from '../../../../embedding/types.js';
|
|
7
|
+
import type { PortableContract, PublishedDatadogAppInput } from '../../../published-definition.js';
|
|
8
|
+
import type { DatadogAppInputsHostValues } from '../../../types.js';
|
|
9
|
+
type Payload0 = {
|
|
10
|
+
"timeframe": Payload1;
|
|
11
|
+
"templateVariables": Payload3;
|
|
12
|
+
};
|
|
13
|
+
type Payload1 = {
|
|
14
|
+
"start": number;
|
|
15
|
+
"end": number;
|
|
16
|
+
"isLive": Payload2;
|
|
17
|
+
};
|
|
18
|
+
type Payload2 = false | true;
|
|
19
|
+
type Payload3 = Array<Payload4>;
|
|
20
|
+
type Payload4 = {
|
|
21
|
+
"name": string;
|
|
22
|
+
"value": string;
|
|
23
|
+
"values"?: Payload5;
|
|
24
|
+
"prefix"?: Payload7;
|
|
25
|
+
"default"?: Payload7;
|
|
26
|
+
"availableValues"?: Payload5;
|
|
27
|
+
};
|
|
28
|
+
type Payload5 = undefined | Payload6;
|
|
29
|
+
type Payload6 = Array<string>;
|
|
30
|
+
type Payload7 = undefined | string;
|
|
31
|
+
type Current = PortableContract<"datadog.notebook", 1, {
|
|
32
|
+
"notebook": ValueField<ValueSchema<Payload0>>;
|
|
33
|
+
}>;
|
|
34
|
+
export declare const datadogNotebook: PublishedDatadogAppInput<Current, readonly ["datadog.notebook"]>;
|
|
35
|
+
export type NotebookInputs = DatadogAppInputsHostValues<typeof datadogNotebook>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0.
|
|
2
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
3
|
+
* Copyright 2019-Present Datadog, Inc.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ValueSchema, ValueField, FunctionField } from '../../../../embedding/types.js';
|
|
7
|
+
import type { PortableContract, PublishedDatadogAppInput } from '../../../published-definition.js';
|
|
8
|
+
import type { DatadogAppInputsHostValues } from '../../../types.js';
|
|
9
|
+
type Current = PortableContract<"datadog.idp.service-panel", 1, {
|
|
10
|
+
"service": ValueField<ValueSchema<string>>;
|
|
11
|
+
"close": FunctionField<{}, ValueSchema<undefined>>;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const datadogServicePanel: PublishedDatadogAppInput<Current, readonly ["datadog.idp.service-panel"]>;
|
|
14
|
+
export type ServicePanelInputs = DatadogAppInputsHostValues<typeof datadogServicePanel>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0.
|
|
2
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
3
|
+
* Copyright 2019-Present Datadog, Inc.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ValueSchema, ValueField } from '../../../../embedding/types.js';
|
|
7
|
+
import type { PortableContract, PublishedDatadogAppInput } from '../../../published-definition.js';
|
|
8
|
+
import type { DatadogAppInputsHostValues } from '../../../types.js';
|
|
9
|
+
type Payload0 = "light" | "dark";
|
|
10
|
+
type Current = PortableContract<"datadog.theme", 1, {
|
|
11
|
+
"theme": ValueField<ValueSchema<Payload0>>;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const datadogTheme: PublishedDatadogAppInput<Current, readonly ["datadog.idp.homepage", "datadog.idp.service-panel", "datadog.idp.self-service", "datadog.app-builder", "datadog.appsec", "datadog.notebook", "datadog.dashboard"]>;
|
|
14
|
+
export type DatadogAppTheme = DatadogAppInputsHostValues<typeof datadogTheme>['theme'];
|
|
15
|
+
export {};
|
|
@@ -3,23 +3,4 @@
|
|
|
3
3
|
* Copyright 2019-Present Datadog, Inc.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
* `@datadog/apps-frontend/inputs/schema`'s npm entry. Anything defined under
|
|
8
|
-
* this directory that should reach consumers of the published package must
|
|
9
|
-
* be exported from this file -- not from any individual schema module.
|
|
10
|
-
*
|
|
11
|
-
* Exporting a schema here is the whole of publishing it:
|
|
12
|
-
* `DatadogAppInputDefinition` is derived from what this file hands out, so the
|
|
13
|
-
* hook accepts exactly that and nothing else.
|
|
14
|
-
*/
|
|
15
|
-
import type { AnyDatadogAppInputsSchema } from '../published-definition.js';
|
|
16
|
-
export { datadogTheme } from './theme.js';
|
|
17
|
-
export type { DatadogAppTheme } from './theme.js';
|
|
18
|
-
export { datadogDashboard } from './dashboard.js';
|
|
19
|
-
export type { DashboardInputs } from './dashboard.js';
|
|
20
|
-
/**
|
|
21
|
-
* Every published input an app may claim -- read off this module's own exports,
|
|
22
|
-
* so exporting a schema above is the whole of publishing it. There is no second
|
|
23
|
-
* list to keep in step, and `useDatadogAppInput` widens automatically.
|
|
24
|
-
*/
|
|
25
|
-
export type DatadogAppInputDefinition = Extract<(typeof import('./index.js'))[keyof typeof import('./index.js')], AnyDatadogAppInputsSchema>;
|
|
6
|
+
export * from './generated/consumers/index.js';
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* Copyright 2019-Present Datadog, Inc.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import{a,b}from"../../_chunks/chunk-
|
|
6
|
+
import{a,b,c,d}from"../../_chunks/chunk-DETZPDFA.js";import"../../_chunks/chunk-EYBITW7J.js";import"../../_chunks/chunk-OEPH347K.js";import"../../_chunks/chunk-LEEYMNMO.js";export{b as datadogDashboard,c as datadogNotebook,d as datadogServicePanel,a as datadogTheme};
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Copyright 2019-Present Datadog, Inc.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { AnyContract, AnyField,
|
|
7
|
-
import type { UnionToIntersection } from '../embedding/versioning.js';
|
|
6
|
+
import type { AnyContract, AnyField, ClaimedValues, FunctionField, FunctionInputs, HostFunctionContext, InferOf, ValueField } from '../embedding/types.js';
|
|
7
|
+
import type { AnyVersionedContract, UnionToIntersection } from '../embedding/versioning.js';
|
|
8
8
|
/**
|
|
9
9
|
* Anything a host supplies values for: one flat namespace of fields. An
|
|
10
10
|
* inputs definition satisfies this with the union of every version's fields,
|
|
@@ -39,12 +39,24 @@ export type FieldsHostImplementation<TFields extends Record<string, AnyField>> =
|
|
|
39
39
|
* versions need, with nothing marking which is which.
|
|
40
40
|
*/
|
|
41
41
|
export type DatadogAppInputImplementations<TSchema extends AnyFieldsOwner> = FieldsHostImplementation<TSchema['fields']>;
|
|
42
|
-
export type DatadogAppInputValueUpdates<TSchema extends AnyFieldsOwner> = Readonly<{
|
|
43
|
-
[TKey in keyof TSchema['fields'] as TSchema['fields'][TKey] extends ValueField<AnySchema> ? TKey : never]: TSchema['fields'][TKey] extends ValueField<infer TSchema2> ? InferOf<TSchema2> : never;
|
|
44
|
-
}>;
|
|
45
42
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
43
|
+
* A retained contract derives ordinary values and callbacks from current inputs
|
|
44
|
+
* and its named extras. Conversion is synchronous and pure; returned callbacks
|
|
45
|
+
* may be asynchronous and receive the original host context.
|
|
48
46
|
*/
|
|
47
|
+
export interface RetainedDatadogAppInputsVersion<TCurrent extends AnyContract, TRetained extends AnyContract, TExtras extends Record<string, AnyField>> {
|
|
48
|
+
readonly contract: TRetained;
|
|
49
|
+
readonly extraInputs: TExtras;
|
|
50
|
+
convert(current: FieldsHostImplementation<TCurrent['fields']>, extra: FieldsHostImplementation<TExtras>): FieldsHostImplementation<TRetained['fields']>;
|
|
51
|
+
}
|
|
52
|
+
/** A host-side definition and its complete, plain implementations. */
|
|
53
|
+
export interface DatadogAppInputBinding<TDefinition extends AnyVersionedContract> {
|
|
54
|
+
readonly definition: TDefinition;
|
|
55
|
+
readonly values: DatadogAppInputImplementations<TDefinition>;
|
|
56
|
+
}
|
|
57
|
+
export type DatadogAppInputValueUpdates<TSchema extends AnyFieldsOwner> = Readonly<{
|
|
58
|
+
[TKey in keyof TSchema['fields'] as TSchema['fields'][TKey]['kind'] extends 'value' ? TKey : never]: TSchema['fields'][TKey] extends ValueField<infer TSchema2> ? InferOf<TSchema2> : never;
|
|
59
|
+
}>;
|
|
60
|
+
/** `update()` accepts a partial record of value fields; callbacks stay session-stable. */
|
|
49
61
|
export type DatadogAppInputPartialValueUpdates<TSchema extends AnyFieldsOwner> = Partial<DatadogAppInputValueUpdates<TSchema>>;
|
|
50
62
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/apps-frontend",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "React inputs for Datadog Apps",
|
|
6
6
|
"homepage": "https://datadoghq.com",
|
|
@@ -81,6 +81,9 @@
|
|
|
81
81
|
},
|
|
82
82
|
"scripts": {
|
|
83
83
|
"build": "node build.cjs",
|
|
84
|
+
"generate:inputs": "node src/inputs/schemas/tooling/generate.cjs --write",
|
|
85
|
+
"check:inputs": "node src/inputs/schemas/tooling/generate.cjs --check",
|
|
86
|
+
"test:inputs-codegen": "node --test src/inputs/schemas/tooling/*.test.cjs",
|
|
84
87
|
"lint": "lint:workspace",
|
|
85
88
|
"test-unit": "test-unit:workspace",
|
|
86
89
|
"typecheck": "typecheck:workspace"
|
|
@@ -104,7 +107,7 @@
|
|
|
104
107
|
"typescript": "patch:typescript%40npm%3A6.0.2#~/.yarn/patches/typescript-npm-6.0.2-no-dts-errors.patch"
|
|
105
108
|
},
|
|
106
109
|
"peerDependencies": {
|
|
107
|
-
"@datadog/druids": ">=0.0.7 <0.
|
|
110
|
+
"@datadog/druids": ">=0.0.7 <0.2.0",
|
|
108
111
|
"react": "^18.0.0 || ^19.0.0"
|
|
109
112
|
},
|
|
110
113
|
"peerDependenciesMeta": {
|