@datadog/webpack-plugin 3.3.2-dev.0 → 3.3.2-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/apps-runtime.mjs +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +1 -1
- package/dist/src/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
class
|
|
1
|
+
class t extends Error{constructor(t,e,n){super(t),this.functionName=e,this.statusCode=n,this.name="BackendFunctionError"}}const e=async(e,n)=>{const o={functionName:e,args:n};let r,i;try{r=await fetch("/__dd/executeAction",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)})}catch(n){throw new t(`Network error while executing backend function "${e}": ${n instanceof Error?n.message:String(n)}`,e)}if(!r.ok){let n=`Backend function "${e}" failed with status ${r.status}`;try{const t=await r.text();t&&(n+=`: ${t}`)}catch{}throw new t(n,e,r.status)}try{i=await r.json()}catch(n){throw new t(`Failed to parse response from backend function "${e}": ${n instanceof Error?n.message:String(n)}`,e,r.status)}if(!i.success)throw new t(`Backend function "${e}" returned an error: ${i.error}`,e,r.status);return i.result.data},n=["datadoghq.com","us3.datadoghq.com","us5.datadoghq.com","datadoghq.eu","ddog-gov.com","us2.ddog-gov.com","ap1.datadoghq.com","ap2.datadoghq.com","datad0g.com"];let o=0;function r(){return"undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():(o+=1,`req-${Date.now()}-${o}`)}function i(t){let e;try{e=new URL(t)}catch{return!1}return"https:"===e.protocol&&""===e.port&&void 0!==(t=>{if("string"!=typeof t)return;const e=t.toLowerCase(),o=n.find((t=>t===e));if(o)return{site:o};const r=n.filter((t=>e.endsWith(`.${t}`)));if(!r.length)return;const i=r.reduce(((t,e)=>e.length>t.length?e:t)),a=e.slice(0,e.length-i.length-1);return a&&/^[a-z0-9-]+$/.test(a)?{site:i,subdomain:a}:void 0})(e.hostname)}const a=new WeakMap;async function s(){const t=window.location.ancestorOrigins;if(t)return t[0];if(window.parent===window)return;let e=a.get(window);void 0===e&&(e=function(){const t=r();return new Promise((e=>{function n(t){window.removeEventListener("message",o),clearTimeout(r),e(t)}function o(e){e.source===window.parent&&function(t,e){return null!==t&&"object"==typeof t&&"type"in t&&"app-builder:pong"===t.type&&"requestId"in t&&t.requestId===e}(e.data,t)&&n(e.origin)}window.addEventListener("message",o);const r=setTimeout((()=>n(void 0)),2e3),i={type:"app-builder:ping",requestId:t};try{window.parent.postMessage(i,"*")}catch{n(void 0)}}))}(),a.set(window,e));const n=await e;return void 0===n&&a.get(window)===e&&a.delete(window),n}function c(t,e){console.warn(`[dd-apps] Sending "${t}" without its dev server bundle: ${e}`)}async function d(t){const e={functionName:t},n=JSON.stringify(e),o=new AbortController,r=setTimeout((()=>{const t=new Error("timed out after 60000ms");o.abort(t)}),6e4);try{const e=await fetch("/__dd/debugBundle",{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:n,signal:o.signal});if(!e.ok){const n=await async function(t){const e=`HTTP ${t.status}`;try{const n=await t.json();return null!==n&&"object"==typeof n&&"error"in n&&"string"==typeof n.error?`${e}: ${n.error}`:e}catch{return e}}(e);return void c(t,n)}const r=await e.json();return null!==(i=r)&&"object"==typeof i&&"code"in i&&"string"==typeof i.code&&i.code.length>0&&"allowedConnectionIds"in i&&Array.isArray(i.allowedConnectionIds)&&i.allowedConnectionIds.every((t=>"string"==typeof t))?{code:r.code,allowedConnectionIds:r.allowedConnectionIds}:void c(t,"the dev server response is not a bundle")}catch(e){return void c(t,e instanceof Error?e.message:String(e))}finally{clearTimeout(r)}var i}const u=async(e,n)=>{const o=r(),a=await async function(){if(!0!==Reflect.get(globalThis,"DD_APPS_DEV_SERVER"))return;const t=await s();return void 0!==t&&i(t)?t:void 0}(),c=void 0===a?void 0:await d(e);return new Promise(((r,i)=>{let s;function d(){window.removeEventListener("message",u),clearTimeout(s)}function u(n){if(!function(t,e){return null!==t&&"object"==typeof t&&"type"in t&&"app-builder:run-query:response"===t.type&&"requestId"in t&&t.requestId===e}(n.data,o))return;d();const a=n.data;a.success?r(a.result.data):i(new t(a.error??`Backend function "${e}" failed`,e))}window.addEventListener("message",u),s=setTimeout((()=>{d(),i(new t(`Backend function "${e}" timed out waiting for response`,e))}),12e4);const w={type:"app-builder:run-query",requestId:o,queryName:e,args:n,...c&&{bundle:c}},l=a??"*";try{window.parent.postMessage(w,l)}catch(t){d(),i(t)}}))};function w(){return function(){try{return"undefined"!=typeof window&&window.parent!==window}catch{return!0}}()?u:e}globalThis.DD_APPS_RUNTIME={executeBackendFunction:async function(t,e){return w()(t,e)}};
|