@cloudquery/plugin-config-ui-lib
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -17,2 +17,25 @@ import { FormMessagePayload } from '@cloudquery/plugin-config-ui-connector'; | ||
/** | ||
* This hook is used to make API calls that require Authentication header from CloudQuery Cloud App. | ||
* It sends an `api_call_request` message to the CloudQuery Cloud App with the endpoint, method, body, and options. | ||
* It subscribes to the `api_call_response` message to get the response from the CloudQuery Cloud App. | ||
* | ||
* @public | ||
*/ | ||
export declare function useApiCall<ResponseData>(pluginUiMessageHandler: PluginUiMessageHandler): { | ||
callApi: (endpoint: string, method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE", body: any, options: { | ||
headers?: HeadersInit; | ||
mode?: RequestMode; | ||
}) => { | ||
requestPromise: Promise<{ | ||
body: ResponseData; | ||
endpoint: string; | ||
headers: HeadersInit; | ||
status: number; | ||
}>; | ||
abortRequest: () => void; | ||
requestId: string; | ||
}; | ||
}; | ||
/** | ||
* This hook is used to notify CloudQuery Cloud App | ||
@@ -19,0 +42,0 @@ * about the height change of the plugin UI form. |
@@ -1,2 +0,2 @@ | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("react"));else if("function"==typeof define&&define.amd)define(["react"],t);else{var n="object"==typeof exports?t(require("react")):t(e.react);for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(this,(e=>(()=>{"use strict";var t={155:t=>{t.exports=e}},n={};function o(e){var r=n[e];if(void 0!==r)return r.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,o),i.exports}o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};o.r(r),o.d(r,{useFormHeightChange:()=>s,useFormInit:()=>a,useFormSubmit:()=>c});var i=o(155);function s(e){const t=(0,i.useRef)(null);return(0,i.useEffect)((()=>{var n,o,r;const i=new ResizeObserver((()=>{var n,o;e.sendMessage("height_changed",{height:null!==(o=null===(n=t.current)||void 0===n?void 0:n.offsetHeight)&&void 0!==o?o:0})}));return i.observe(null!==(n=t.current)&&void 0!==n?n:document.body),e.sendMessage("height_changed",{height:null!==(r=null===(o=t.current)||void 0===o?void 0:o.offsetHeight)&&void 0!==r?r:0}),()=>{i.disconnect()}}),[e]),t}function a(e,t){const[n,o]=(0,i.useState)(!1),[r,s]=(0,i.useState)(),[a,u]=(0,i.useState)("");return(0,i.useEffect)((()=>e.subscribeToMessageOnce("init",(({initialValues:n})=>{var r;(null===(r=null==n?void 0:n.spec)||void 0===r?void 0:r.connection_string)&&s(n),e.subscribeToMessage("name_changed",(({name:e})=>{u(e)})),o(!0),e.sendMessage("ready",{implementsCustomFooter:t})}))),[]),{initialized:n,initialValues:r,name:a}}var u=function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{u(o.next(e))}catch(e){i(e)}}function a(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((o=o.apply(e,t||[])).next())}))};function c(e,t){(0,i.useEffect)((()=>t.subscribeToMessage("validate",(()=>u(this,void 0,void 0,(function*(){const{errors:n,values:o}=yield e();n?t.sendMessage("validation_failed",{errors:n}):t.sendMessage("validation_passed",{values:o})}))))),[e,t])}return r})())); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("react"));else if("function"==typeof define&&define.amd)define(["react"],t);else{var n="object"==typeof exports?t(require("react")):t(e.react);for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(this,(e=>(()=>{"use strict";var t={155:t=>{t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var s=n[e]={exports:{}};return t[e](s,s.exports,r),s.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};r.r(o),r.d(o,{useApiCall:()=>i,useFormHeightChange:()=>u,useFormInit:()=>a,useFormSubmit:()=>d});var s=r(155);function i(e){const t=(0,s.useRef)([]),n=(0,s.useCallback)(((n,r,o,s)=>{let i,u=null;const a=Math.random().toString(36).slice(7),c=new Promise(((c,d)=>{i=d,e.sendMessage("api_call_request",{endpoint:n,method:r,id:a,body:o,options:s}),u=e.subscribeToMessage("api_call_response",(({endpoint:e,headers:n,id:r,ok:o,status:s,body:i})=>{r===a&&(u(),t.current=t.current.filter((e=>e!==u)),o?c({body:i,endpoint:e,headers:n,status:s}):d({body:i,endpoint:e,headers:n,status:s}))})),t.current.push(u)}));return{requestPromise:c,abortRequest:()=>{u(),t.current=t.current.filter((e=>e!==u)),e.sendMessage("api_call_abort_request",{id:a}),i({body:null,endpoint:n,headers:null,status:0})},requestId:a}}),[e]);return(0,s.useEffect)((()=>()=>{for(const e of t.current)e&&e()}),[]),{callApi:n}}function u(e){const t=(0,s.useRef)(null);return(0,s.useEffect)((()=>{var n,r,o;const s=new ResizeObserver((()=>{var n,r;e.sendMessage("height_changed",{height:null!==(r=null===(n=t.current)||void 0===n?void 0:n.offsetHeight)&&void 0!==r?r:0})}));return s.observe(null!==(n=t.current)&&void 0!==n?n:document.body),e.sendMessage("height_changed",{height:null!==(o=null===(r=t.current)||void 0===r?void 0:r.offsetHeight)&&void 0!==o?o:0}),()=>{s.disconnect()}}),[e]),t}function a(e,t){const[n,r]=(0,s.useState)(!1),[o,i]=(0,s.useState)(),[u,a]=(0,s.useState)("");return(0,s.useEffect)((()=>e.subscribeToMessageOnce("init",(({initialValues:n})=>{var o;(null===(o=null==n?void 0:n.spec)||void 0===o?void 0:o.connection_string)&&i(n),e.subscribeToMessage("name_changed",(({name:e})=>{a(e)})),r(!0),e.sendMessage("ready",{implementsCustomFooter:t})}))),[]),{initialized:n,initialValues:o,name:u}}var c=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{a(r.next(e))}catch(e){s(e)}}function u(e){try{a(r.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,u)}a((r=r.apply(e,t||[])).next())}))};function d(e,t){(0,s.useEffect)((()=>t.subscribeToMessage("validate",(()=>c(this,void 0,void 0,(function*(){const{errors:n,values:r}=yield e();n?t.sendMessage("validation_failed",{errors:n}):t.sendMessage("validation_passed",{values:r})}))))),[e,t])}return o})())); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@cloudquery/plugin-config-ui-lib", | ||
"description": "Plugin configuration UI library for CloudQuery Cloud App", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
41853
76