@tachybase/plugin-action-custom-request 0.23.48 → 1.0.6
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/client/components/CustomRequestAfter.d.ts +1 -0
- package/dist/client/components/CustomResponseTemplate.d.ts +5 -0
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +10 -10
- package/dist/locale/zh-CN.json +3 -0
- package/dist/server/actions/send.js +14 -6
- package/package.json +12 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function CustomRequestAfter(): import("react/jsx-runtime").JSX.Element;
|
package/dist/client/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(o,r){typeof exports=="object"&&typeof module!="undefined"?r(exports,require("react/jsx-runtime"),require("@tachybase/client"),require("@tachybase/schema"),require("@tachybase/utils/client"),require("antd"),require("react-router-dom"),require("react-i18next"),require("react"),require("@tachybase/components")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@tachybase/client","@tachybase/schema","@tachybase/utils/client","antd","react-router-dom","react-i18next","react","@tachybase/components"],r):(o=typeof globalThis!="undefined"?globalThis:o||self,r(o["@tachybase/plugin-action-custom-request"]={},o.jsxRuntime,o["@tachybase/client"],o["@tachybase/schema"],o["@tachybase/utils"],o.antd,o["react-router-dom"],o["react-i18next"],o.react,o["@tachybase/components"]))})(this,function(o,r,e,l,T,S,B,I,b,F){"use strict";var ge=Object.defineProperty,be=Object.defineProperties;var Re=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var se=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable;var oe=(o,r,e)=>r in o?ge(o,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[r]=e,v=(o,r)=>{for(var e in r||(r={}))se.call(r,e)&&oe(o,e,r[e]);if(D)for(var e of D(r))ne.call(r,e)&&oe(o,e,r[e]);return o},A=(o,r)=>be(o,Re(r));var re=(o,r)=>{var e={};for(var l in o)se.call(o,l)&&r.indexOf(l)<0&&(e[l]=o[l]);if(o!=null&&D)for(var l of D(o))r.indexOf(l)<0&&ne.call(o,l)&&(e[l]=o[l]);return e};var q=(o,r,e)=>new Promise((l,T)=>{var S=b=>{try{I(e.next(b))}catch(F){T(F)}},B=b=>{try{I(e.throw(b))}catch(F){T(F)}},I=b=>b.done?l(b.value):Promise.resolve(b.value).then(S,B);I((e=e.apply(o,r)).next())});const P="customRequests:listByCurrentRole";var O=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},z={exports:{}};(function(s,m){(function(i,c){c()})(O,function(){function i(n,a){return typeof a=="undefined"?a={autoBom:!1}:typeof a!="object"&&(console.warn("Deprecated: Expected third argument to be a object"),a={autoBom:!a}),a.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(n.type)?new Blob(["\uFEFF",n],{type:n.type}):n}function c(n,a,h){var u=new XMLHttpRequest;u.open("GET",n),u.responseType="blob",u.onload=function(){x(u.response,a,h)},u.onerror=function(){console.error("could not download file")},u.send()}function p(n){var a=new XMLHttpRequest;a.open("HEAD",n,!1);try{a.send()}catch(h){}return 200<=a.status&&299>=a.status}function d(n){try{n.dispatchEvent(new MouseEvent("click"))}catch(h){var a=document.createEvent("MouseEvents");a.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),n.dispatchEvent(a)}}var f=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof O=="object"&&O.global===O?O:void 0,g=f.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),x=f.saveAs||(typeof window!="object"||window!==f?function(){}:"download"in HTMLAnchorElement.prototype&&!g?function(n,a,h){var u=f.URL||f.webkitURL,C=document.createElement("a");a=a||n.name||"download",C.download=a,C.rel="noopener",typeof n=="string"?(C.href=n,C.origin===location.origin?d(C):p(C.href)?c(n,a,h):d(C,C.target="_blank")):(C.href=u.createObjectURL(n),setTimeout(function(){u.revokeObjectURL(C.href)},4e4),setTimeout(function(){d(C)},0))}:"msSaveOrOpenBlob"in navigator?function(n,a,h){if(a=a||n.name||"download",typeof n!="string")navigator.msSaveOrOpenBlob(i(n,h),a);else if(p(n))c(n,a,h);else{var u=document.createElement("a");u.href=n,u.target="_blank",setTimeout(function(){d(u)})}}:function(n,a,h,u){if(u=u||open("","_blank"),u&&(u.document.title=u.document.body.innerText="downloading..."),typeof n=="string")return c(n,a,h);var C=n.type==="application/octet-stream",L=/constructor/i.test(f.HTMLElement)||f.safari,w=/CriOS\/[\d]+/.test(navigator.userAgent);if((w||C&&L||g)&&typeof FileReader!="undefined"){var U=new FileReader;U.onloadend=function(){var R=U.result;R=w?R:R.replace(/^data:[^;]*;/,"data:attachment/file;"),u?u.location.href=R:location=R,u=null},U.readAsDataURL(n)}else{var j=f.URL||f.webkitURL,t=j.createObjectURL(n);u?u.location=t:location.href=t,u=null,setTimeout(function(){j.revokeObjectURL(t)},4e4)}});f.saveAs=x.saveAs=x,s.exports=x})})(z);var ae=z.exports;const H="action-custom-request";function y(s){return`{{t('${s}', { ns: '${H}', nsMode: 'fallback' })}}`}function k(){return I.useTranslation(H,{nsMode:"fallback"})}const ie=()=>{const s=e.useAPIClient(),m=B.useNavigate(),i=l.useFieldSchema(),c=e.useCompile(),p=l.useForm(),{getPrimaryKey:d}=e.useCollection_deprecated(),{resource:f,__parent:g,service:x}=e.useBlockRequestContext(),n=e.useRecord(),a=l.useFieldSchema(),h=l.useField(),{setVisible:u}=e.useActionContext(),{modal:C,message:L}=S.App.useApp(),{t:w}=k();return{onClick(){return q(this,null,function*(){var X,Q,Y,M,Z,ee,te;const{skipValidator:j,onSuccess:t}=(X=i==null?void 0:i["x-action-settings"])!=null?X:{},R=i==null?void 0:i["x-action"];j!==!0&&R==="customize:form:request"&&(yield p.submit());let W={};R==="customize:form:request"&&(W=p.values),(Q=h.data)!=null||(h.data={}),h.data.loading=!0;try{const V=yield s.request({url:`/customRequests:send/${a["x-uid"]}`,method:"POST",responseType:t!=null&&t.down?"blob":"json",data:{currentRecord:{id:n[d()],appends:(Y=x.params[0])==null?void 0:Y.appends,data:W}}}),Ce=V.headers.getContentType();if(t!=null&&t.down)if(Ce==="application/octet-stream"){const xe=t.downTitle;ae.saveAs(V.data,xe)}else L.error(w("The current return type is not a document type"));if(h.data.loading=!1,f instanceof e.TableFieldResource||(Z=(M=g==null?void 0:g.service)==null?void 0:M.refresh)==null||Z.call(M),(ee=x==null?void 0:x.refresh)==null||ee.call(x),R==="customize:form:request"&&(u==null||u(!1)),(te=i==null?void 0:i["x-component-props"])!=null&&te.showData)C.confirm({title:"Test Data",content:`${JSON.stringify(V.data)}`,okText:w("Confirm"),cancelText:w("Cancel")});else{if(!(t!=null&&t.successMessage))return;t!=null&&t.manualClose?C.success({title:c(t==null?void 0:t.successMessage),onOk:()=>q(this,null,function*(){t!=null&&t.redirecting&&(t!=null&&t.redirectTo)&&(T.isURL(t.redirectTo)?window.location.href=t.redirectTo:m(t.redirectTo))})}):(L.success(c(t==null?void 0:t.successMessage)),t!=null&&t.redirecting&&(t!=null&&t.redirectTo)&&(T.isURL(t.redirectTo)?window.location.href=t.redirectTo:m(t.redirectTo)))}}finally{h.data.loading=!1}})}}},K=()=>{const m=`customRequests:get/${l.useFieldSchema()["x-uid"]}`;return e.useRequest({url:m,params:{appends:["roles"]}},{manual:!0,cacheKey:m})},ue=()=>{const s=e.useCollection_deprecated(),{t:m}=k(),i=e.useCollectionFilterOptions(s),c=e.useCollectionFilterOptions("users"),p=e.useCompile(),[d,f]=b.useMemo(()=>[p(i),p(c)],[i,c]);return b.useMemo(()=>[{name:"currentRecord",title:m("Current record",{ns:"core"}),children:[...d]},{name:"currentUser",title:m("Current user",{ns:"core"}),children:f},{name:"currentTime",title:m("Current time",{ns:"core"}),children:null}],[d,f])},E=()=>e.useAPIClient().resource("customRequests"),_={type:"object",properties:{method:{type:"string",required:!0,title:y("HTTP method"),"x-decorator-props":{tooltip:y("When the HTTP method is Post, Put or Patch, and this custom request inside the form, the request body will be automatically filled in with the form data")},"x-decorator":"FormItem","x-component":"Select","x-component-props":{showSearch:!1,allowClear:!1,className:"auto-width"},enum:[{label:"GET",value:"GET"},{label:"POST",value:"POST"},{label:"PUT",value:"PUT"},{label:"PATCH",value:"PATCH"},{label:"DELETE",value:"DELETE"}],default:"POST"},url:{type:"string",required:!0,title:y("URL"),"x-decorator":"FormItem","x-component":"Variable.RawTextArea","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",autoSize:!0,fieldNames:{value:"name",label:"title"},placeholder:"https://www.tachybase.com"}},headers:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:y("Headers"),description:y('"Content-Type" only support "application/json", and no need to specify'),items:{type:"object",properties:{space:{type:"void","x-component":"Space",properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:y("Name")}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.Input","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",fieldNames:{value:"name",label:"title"},useTypedConstant:!0}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:y("Add request header"),"x-component":"ArrayItems.Addition"}}},params:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:y("Parameters"),items:{type:"object",properties:{space:{type:"void","x-component":"Space",properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:y("Name")}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.Input","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",fieldNames:{value:"name",label:"title"},useTypedConstant:!0}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:y("Add parameter"),"x-component":"ArrayItems.Addition"}}},data:{type:"string",title:y("Body"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"Variable.JSON","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",fieldNames:{value:"name",label:"title"},changeOnSelect:!0,autoSize:{minRows:10},placeholder:y("Input request data")},description:y("Only support standard JSON data")},timeout:{type:"number",title:y("Timeout config"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"InputNumber","x-component-props":{addonAfter:y("ms"),min:1,step:1e3,defaultValue:5e3}}}},ce={type:"object",properties:{roles:{type:"array",title:y("Roles"),"x-decorator":"FormItem","x-decorator-props":{tooltip:y("If not set, all roles can see this action")},"x-component":"RemoteSelect","x-component-props":{multiple:!0,objectValue:!0,service:{resource:"roles"},manual:!1,fieldNames:{label:"title",value:"name"}}}}};function G(){var g;const{t:s}=k(),{name:m}=e.useCollection_deprecated(),i=l.useFieldSchema(),c=E(),{message:p}=S.App.useApp(),{data:d,refresh:f}=K();return r.jsx(r.Fragment,{children:r.jsx(e.SchemaSettingsActionModalItem,{title:s("Request settings"),components:{ArrayItems:F.ArrayItems},beforeOpen:()=>!d&&f(),scope:{useCustomRequestVariableOptions:ue},schema:_,initialValues:v({},(g=d==null?void 0:d.data)==null?void 0:g.options),onSubmit:x=>q(this,null,function*(){const n=re(x,[]);return yield c.updateOrCreate({values:{key:i["x-uid"],options:A(v({},n),{collectionName:m})},filterKeys:["key"]}),f(),p.success(s("Saved successfully"))})})})}function $(){var g;const{t:s}=k(),m=l.useFieldSchema(),i=E(),{message:c}=S.App.useApp(),{data:p,refresh:d}=K(),{refresh:f}=e.useRequest({url:P},{manual:!0,cacheKey:P});return r.jsx(r.Fragment,{children:r.jsx(e.SchemaSettingsActionModalItem,{title:s("Access control"),schema:ce,initialValues:{roles:(g=p==null?void 0:p.data)==null?void 0:g.roles},beforeOpen:()=>!p&&d(),onSubmit:n=>q(this,[n],function*({roles:x}){return yield i.updateOrCreate({values:{key:m["x-uid"],roles:x},filterKeys:["key"]}),d(),f(),c.success(s("Saved successfully"))})})})}const le=new e.SchemaSettings({name:"CustomRequestActionSettings",items:[A(v({},e.actionSettingsItems[0]),{children:[...e.actionSettingsItems[0].children,{name:"request settings",Component:G},{name:"accessControl",Component:$}]})]}),me=()=>{const s=E(),m=l.useFieldSchema();return r.jsx(e.Action.Designer,{linkageAction:!0,schemaSettings:"CustomRequestActionSettings",buttonEditorProps:{isLink:m["x-action"]==="customize:table:request"},linkageRulesProps:{type:"button"},removeButtonProps:{onConfirmOk(){return s.destroy({filterByTk:m["x-uid"]})}}})},pe=s=>{var d;const i=e.useAPIClient().auth.role==="root",c=l.useFieldSchema(),{data:p}=e.useRequest({url:P},{manual:i,cacheKey:P});return!i&&!((d=p==null?void 0:p.data)!=null&&d.includes(c==null?void 0:c["x-uid"]))?null:s.children},de={"customize:table:request":e.Action.Link},N=s=>{const i=l.useFieldSchema()["x-action"],c=de[i]||e.Action;return r.jsx(c,A(v({},s),{useProps:ie}))};N.Designer=me,N.Decorator=pe;const fe=s=>{const m=E(),i={title:'{{ t("Custom request") }}',"x-component":"CustomRequestAction","x-action":"customize:form:request","x-toolbar":"ActionSchemaToolbar","x-settings":"actionSettings:customRequest","x-decorator":"CustomRequestAction.Decorator","x-uid":l.uid(),"x-action-settings":{onSuccess:{manualClose:!1,redirecting:!1,successMessage:'{{t("Request success")}}'}}},c=e.useSchemaInitializerItem();return r.jsx(e.BlockInitializer,A(v({},c),{item:c,onClick:p=>q(this,null,function*(){yield m.create({values:{key:p["x-uid"]}})}),schema:i}))},ye=new e.SchemaSettings({name:"actionSettings:customRequest",items:[{name:"editButton",Component:e.ButtonEditor,useComponentProps(){const{buttonEditorProps:s}=e.useSchemaToolbar();return v({isLink:!0},s)}},{name:"linkageRules",Component:e.SchemaSettingsLinkageRules,useComponentProps(){const{name:s}=e.useCollection(),{linkageRulesProps:m}=e.useSchemaToolbar();return A(v({},m),{collectionName:s})}},{name:"secondConFirm",Component:e.SecondConFirm},{name:"isDownLoad",Component:e.IsDownLoad},{name:"settingDownTitle",Component:e.SettingDownTitle,useVisible(){var i,c;const s=l.useFieldSchema();return(c=(i=s==null?void 0:s["x-action-settings"])==null?void 0:i.onSuccess)==null?void 0:c.down}},{name:"showData",Component:e.ShowData},{name:"afterSuccessfulSubmission",Component:e.AfterSuccess},{name:"request settings",Component:G},{name:"accessControl",Component:$},{name:"delete",sort:100,Component:e.RemoveButton,useComponentProps(){const{removeButtonProps:s}=e.useSchemaToolbar();return s}}]}),he=s=>r.jsx(e.SchemaComponentOptions,{scope:{CustomRequestConfigurationFieldsSchema:_},components:{CustomRequestAction:N,CustomRequestInitializer:fe},children:s.children});class J extends e.Plugin{load(){return q(this,null,function*(){this.app.use(he),this.app.schemaSettingsManager.add(ye),this.app.schemaSettingsManager.add(le)})}}o.CustomRequestPlugin=J,o.default=J,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
(function(n,i){typeof exports=="object"&&typeof module!="undefined"?i(exports,require("react/jsx-runtime"),require("@tachybase/client"),require("@tachybase/schema"),require("@tachybase/utils/client"),require("antd"),require("react-router-dom"),require("react-i18next"),require("react"),require("@tachybase/components")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@tachybase/client","@tachybase/schema","@tachybase/utils/client","antd","react-router-dom","react-i18next","react","@tachybase/components"],i):(n=typeof globalThis!="undefined"?globalThis:n||self,i(n["@tachybase/plugin-action-custom-request"]={},n.jsxRuntime,n["@tachybase/client"],n["@tachybase/schema"],n["@tachybase/utils"],n.antd,n["react-router-dom"],n["react-i18next"],n.react,n["@tachybase/components"]))})(this,function(n,i,e,p,q,k,B,w,g,I){"use strict";var qe=Object.defineProperty,Se=Object.defineProperties;var Te=Object.getOwnPropertyDescriptors;var V=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var se=(n,i,e)=>i in n?qe(n,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[i]=e,v=(n,i)=>{for(var e in i||(i={}))ne.call(i,e)&&se(n,e,i[e]);if(V)for(var e of V(i))re.call(i,e)&&se(n,e,i[e]);return n},A=(n,i)=>Se(n,Te(i));var ae=(n,i)=>{var e={};for(var p in n)ne.call(n,p)&&i.indexOf(p)<0&&(e[p]=n[p]);if(n!=null&&V)for(var p of V(n))i.indexOf(p)<0&&re.call(n,p)&&(e[p]=n[p]);return e};var T=(n,i,e)=>new Promise((p,q)=>{var k=g=>{try{w(e.next(g))}catch(I){q(I)}},B=g=>{try{w(e.throw(g))}catch(I){q(I)}},w=g=>g.done?p(g.value):Promise.resolve(g.value).then(k,B);w((e=e.apply(n,i)).next())});const E="customRequests:listByCurrentRole";var F=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},H={exports:{}};(function(o,r){(function(c,u){u()})(F,function(){function c(s,a){return typeof a=="undefined"?a={autoBom:!1}:typeof a!="object"&&(console.warn("Deprecated: Expected third argument to be a object"),a={autoBom:!a}),a.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(s.type)?new Blob(["\uFEFF",s],{type:s.type}):s}function u(s,a,b){var m=new XMLHttpRequest;m.open("GET",s),m.responseType="blob",m.onload=function(){h(m.response,a,b)},m.onerror=function(){console.error("could not download file")},m.send()}function l(s){var a=new XMLHttpRequest;a.open("HEAD",s,!1);try{a.send()}catch(b){}return 200<=a.status&&299>=a.status}function d(s){try{s.dispatchEvent(new MouseEvent("click"))}catch(b){var a=document.createEvent("MouseEvents");a.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),s.dispatchEvent(a)}}var f=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof F=="object"&&F.global===F?F:void 0,x=f.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),h=f.saveAs||(typeof window!="object"||window!==f?function(){}:"download"in HTMLAnchorElement.prototype&&!x?function(s,a,b){var m=f.URL||f.webkitURL,C=document.createElement("a");a=a||s.name||"download",C.download=a,C.rel="noopener",typeof s=="string"?(C.href=s,C.origin===location.origin?d(C):l(C.href)?u(s,a,b):d(C,C.target="_blank")):(C.href=m.createObjectURL(s),setTimeout(function(){m.revokeObjectURL(C.href)},4e4),setTimeout(function(){d(C)},0))}:"msSaveOrOpenBlob"in navigator?function(s,a,b){if(a=a||s.name||"download",typeof s!="string")navigator.msSaveOrOpenBlob(c(s,b),a);else if(l(s))u(s,a,b);else{var m=document.createElement("a");m.href=s,m.target="_blank",setTimeout(function(){d(m)})}}:function(s,a,b,m){if(m=m||open("","_blank"),m&&(m.document.title=m.document.body.innerText="downloading..."),typeof s=="string")return u(s,a,b);var C=s.type==="application/octet-stream",P=/constructor/i.test(f.HTMLElement)||f.safari,M=/CriOS\/[\d]+/.test(navigator.userAgent);if((M||C&&P||x)&&typeof FileReader!="undefined"){var z=new FileReader;z.onloadend=function(){var R=z.result;R=M?R:R.replace(/^data:[^;]*;/,"data:attachment/file;"),m?m.location.href=R:location=R,m=null},z.readAsDataURL(s)}else{var j=f.URL||f.webkitURL,t=j.createObjectURL(s);m?m.location=t:location.href=t,m=null,setTimeout(function(){j.revokeObjectURL(t)},4e4)}});f.saveAs=h.saveAs=h,o.exports=h})})(H);var ie=H.exports;const G="action-custom-request";function y(o){return`{{t('${o}', { ns: '${G}', nsMode: 'fallback' })}}`}function O(){return w.useTranslation(G,{nsMode:"fallback"})}function ce(o){if(!o)return null;let r=o.match(/filename="([^"]+)"/i);return r?r[1]:(r=o.match(/filename\*=UTF-8''(.+)/i),r?decodeURIComponent(r[1]):null)}const ue=()=>{const o=e.useAPIClient(),r=B.useNavigate(),c=p.useFieldSchema(),u=e.useCompile(),l=p.useForm(),{getPrimaryKey:d}=e.useCollection_deprecated(),{resource:f,__parent:x,service:h}=e.useBlockRequestContext(),s=e.useRecord(),a=p.useFieldSchema(),b=p.useField(),{setVisible:m}=e.useActionContext(),{modal:C,message:P}=k.App.useApp(),{t:M}=O();return{onClick(){return T(this,null,function*(){var Q,Y,Z,N,ee,te;const{skipValidator:j,onSuccess:t}=(Q=c==null?void 0:c["x-action-settings"])!=null?Q:{},R=c==null?void 0:c["x-action"];j!==!0&&R==="customize:form:request"&&(yield l.submit());let W={};R==="customize:form:request"&&(W=l.values),(Y=b.data)!=null||(b.data={}),b.data.loading=!0;try{const U=yield o.request({url:`/customRequests:send/${a["x-uid"]}`,method:"POST",responseType:t!=null&&t.down?"blob":"json",data:{currentRecord:{id:s[d()],appends:(Z=h.params[0])==null?void 0:Z.appends,data:W},successMessage:t.successMessage},headers:{"X-Response-Type":t!=null&&t.down?"blob":"json"}}),Re=U.headers.getContentType();let oe=ce(U.headers["content-disposition"]);if(t!=null&&t.down)if(Re==="application/octet-stream"){const S=t.downTitle;ie.saveAs(U.data,q.parse(S)({filename:oe||""}))}else P.error(M("The current return type is not a document type"));if(b.data.loading=!1,f instanceof e.TableFieldResource||(ee=(N=x==null?void 0:x.service)==null?void 0:N.refresh)==null||ee.call(N),(te=h==null?void 0:h.refresh)==null||te.call(h),R==="customize:form:request"&&(m==null||m(!1)),t!=null&&t.successMessage){let S=q.parse(t==null?void 0:t.successMessage)({res:U,filename:oe});typeof S!="string"&&(S=JSON.stringify(S)),t!=null&&t.manualClose?C.success({title:u(S),onOk:()=>T(this,null,function*(){t!=null&&t.redirecting&&(t!=null&&t.redirectTo)&&(q.isURL(t.redirectTo)?window.location.href=t.redirectTo:r(t.redirectTo))})}):(P.success(u(S)),t!=null&&t.redirecting&&(t!=null&&t.redirectTo)&&(q.isURL(t.redirectTo)?window.location.href=t.redirectTo:r(t.redirectTo)))}else P.success(M("Request success"))}finally{b.data.loading=!1}})}}},K=()=>{const r=`customRequests:get/${p.useFieldSchema()["x-uid"]}`;return e.useRequest({url:r,params:{appends:["roles"]}},{manual:!0,cacheKey:r})},le=()=>{const o=e.useCollection_deprecated(),{t:r}=O(),c=e.useCollectionFilterOptions(o),u=e.useCollectionFilterOptions("users"),l=e.useCompile(),[d,f]=g.useMemo(()=>[l(c),l(u)],[c,u]),x=e.useGlobalVariable("$env");return g.useMemo(()=>{const h=[{name:"currentRecord",title:r("Current record",{ns:"core"}),children:[...d]},{name:"currentUser",title:r("Current user",{ns:"core"}),children:f},{name:"currentTime",title:r("Current time",{ns:"core"}),children:null}];return x&&h.unshift(x),h},[d,f])},L=()=>e.useAPIClient().resource("customRequests"),_={type:"object",properties:{method:{type:"string",required:!0,title:y("HTTP method"),"x-decorator-props":{tooltip:y("When the HTTP method is Post, Put or Patch, and this custom request inside the form, the request body will be automatically filled in with the form data")},"x-decorator":"FormItem","x-component":"Select","x-component-props":{showSearch:!1,allowClear:!1,className:"auto-width"},enum:[{label:"GET",value:"GET"},{label:"POST",value:"POST"},{label:"PUT",value:"PUT"},{label:"PATCH",value:"PATCH"},{label:"DELETE",value:"DELETE"}],default:"POST"},url:{type:"string",required:!0,title:y("URL"),"x-decorator":"FormItem","x-component":"Variable.RawTextArea","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",autoSize:!0,fieldNames:{value:"name",label:"title"},placeholder:"https://www.tachybase.com"}},headers:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:y("Headers"),description:y('"Content-Type" only support "application/json", and no need to specify'),items:{type:"object",properties:{space:{type:"void","x-component":"Space",properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:y("Name")}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.Input","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",fieldNames:{value:"name",label:"title"},useTypedConstant:!0}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:y("Add request header"),"x-component":"ArrayItems.Addition"}}},params:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:y("Parameters"),items:{type:"object",properties:{space:{type:"void","x-component":"Space",properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:y("Name")}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.Input","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",fieldNames:{value:"name",label:"title"},useTypedConstant:!0}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:y("Add parameter"),"x-component":"ArrayItems.Addition"}}},data:{type:"string",title:y("Body"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"Variable.JSON","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",fieldNames:{value:"name",label:"title"},changeOnSelect:!0,autoSize:{minRows:10},placeholder:y("Input request data")},description:y("Only support standard JSON data")},timeout:{type:"number",title:y("Timeout config"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"InputNumber","x-component-props":{addonAfter:y("ms"),min:1,step:1e3,defaultValue:5e3}}}},me={type:"object",properties:{roles:{type:"array",title:y("Roles"),"x-decorator":"FormItem","x-decorator-props":{tooltip:y("If not set, all roles can see this action")},"x-component":"RemoteSelect","x-component-props":{multiple:!0,objectValue:!0,service:{resource:"roles"},manual:!1,fieldNames:{label:"title",value:"name"}}}}};function $(){var h;const{t:o}=O(),{name:r}=e.useCollection_deprecated(),c=p.useFieldSchema(),u=L(),{data:l,refresh:d}=K(),{dn:f}=e.useDesignable(),x=g.useMemo(()=>{var a;const s=v({},(a=l==null?void 0:l.data)==null?void 0:a.options);return s.data&&typeof s.data!="string"&&(s.data=JSON.stringify(s.data,null,2)),s},[(h=l==null?void 0:l.data)==null?void 0:h.options]);return i.jsx(i.Fragment,{children:i.jsx(e.SchemaSettingsActionModalItem,{title:o("Request settings"),components:{ArrayItems:I.ArrayItems},beforeOpen:()=>!l&&d(),scope:{useCustomRequestVariableOptions:le},schema:_,initialValues:x,onSubmit:s=>T(this,null,function*(){const a=ae(s,[]);yield u.updateOrCreate({values:{key:c["x-uid"],options:A(v({},a),{collectionName:r})},filterKeys:["key"]}),f.refresh(),d()})})})}function J(){var x;const{t:o}=O(),r=p.useFieldSchema(),c=L(),{message:u}=k.App.useApp(),{data:l,refresh:d}=K(),{refresh:f}=e.useRequest({url:E},{manual:!0,cacheKey:E});return i.jsx(i.Fragment,{children:i.jsx(e.SchemaSettingsActionModalItem,{title:o("Access control"),schema:me,initialValues:{roles:(x=l==null?void 0:l.data)==null?void 0:x.roles},beforeOpen:()=>!l&&d(),onSubmit:s=>T(this,[s],function*({roles:h}){return yield c.updateOrCreate({values:{key:r["x-uid"],roles:h},filterKeys:["key"]}),d(),f(),u.success(o("Saved successfully"))})})})}const pe=new e.SchemaSettings({name:"CustomRequestActionSettings",items:[A(v({},e.actionSettingsItems[0]),{children:[...e.actionSettingsItems[0].children,{name:"request settings",Component:$},{name:"accessControl",Component:J}]})]}),de=()=>{const o=L(),r=p.useFieldSchema();return i.jsx(e.Action.Designer,{linkageAction:!0,schemaSettings:"CustomRequestActionSettings",buttonEditorProps:{isLink:r["x-action"]==="customize:table:request"},linkageRulesProps:{type:"button"},removeButtonProps:{onConfirmOk(){return o.destroy({filterByTk:r["x-uid"]})}}})},fe=o=>{var d;const c=e.useAPIClient().auth.role==="root",u=p.useFieldSchema(),{data:l}=e.useRequest({url:E},{manual:c,cacheKey:E});return!c&&!((d=l==null?void 0:l.data)!=null&&d.includes(u==null?void 0:u["x-uid"]))?null:o.children},he={"customize:table:request":e.Action.Link},D=o=>{const c=p.useFieldSchema()["x-action"],u=he[c]||e.Action;return i.jsx(u,A(v({},o),{useProps:ue}))};D.Designer=de,D.Decorator=fe;const ye=o=>{const r=L(),c={title:'{{ t("Custom request") }}',"x-component":"CustomRequestAction","x-action":"customize:form:request","x-toolbar":"ActionSchemaToolbar","x-settings":"actionSettings:customRequest","x-decorator":"CustomRequestAction.Decorator","x-uid":p.uid(),"x-action-settings":{onSuccess:{manualClose:!1,redirecting:!1,successMessage:'{{ t("Request success") }}'}}},u=e.useSchemaInitializerItem(),{insert:l}=e.useSchemaInitializer();return i.jsx(e.SchemaInitializerItem,A(v({},u),{onClick:()=>T(this,null,function*(){var f;const d=p.merge(c||{},u.schema||{});(f=u==null?void 0:u.schemaInitialize)==null||f.call(u,d),yield r.create({values:{key:d["x-uid"]}}),l(d)})}))},xe=o=>{const{t:r}=O(),{value:c,onChange:u}=o,l=[{value:"res.data",label:r("Response body")},{value:"filename",label:r("Download file name")}];return i.jsx(e.Variable.CodeMirror,{value:c,onChange:u,scope:l,fieldNames:{value:"value",label:"value"}})},be=o=>({type:"object",title:o("After successful submission"),properties:{down:{title:'{{t("Is DownLoad")}}',"x-decorator":"FormItem","x-component":"Checkbox","x-component-props":{}},downTitle:{title:'{{t("Setting Down Title")}}',default:"{{ filename }}","x-decorator":"FormItem","x-component":"Input","x-component-props":{},"x-reactions":{dependencies:["down"],fulfill:{state:{visible:"{{!!$deps[0]}}"}}}},successMessage:{title:'{{t("Popup message")}}',"x-decorator":"FormItem","x-component":xe,"x-component-props":{}},popupClose:{title:'{{t("Popup close method")}}',enum:[{label:'{{t("Automatic close")}}',value:!1},{label:'{{t("Manually close")}}',value:!0}],"x-decorator":"FormItem","x-component":"Radio.Group","x-component-props":{}},manualClose:{title:'{{t("Message clear metchod")}}',enum:[{label:'{{t("Automatic close")}}',value:!1},{label:'{{t("Manually close")}}',value:!0}],"x-decorator":"FormItem","x-component":"Radio.Group","x-component-props":{}},redirecting:{title:'{{t("Then")}}',enum:[{label:'{{t("Stay on current page")}}',value:!1},{label:'{{t("Redirect to")}}',value:!0}],"x-decorator":"FormItem","x-component":"Radio.Group","x-component-props":{},"x-reactions":{target:"redirectTo",fulfill:{state:{visible:"{{!!$self.value}}"}}}},redirectTo:{title:'{{t("Link")}}',"x-decorator":"FormItem","x-component":"Input","x-component-props":{}}}});function Ce(){var x;const{dn:o}=e.useDesignable(),{t:r}=e.useTranslation(),c=p.useFieldSchema(),u=e.useActionContext(),l=e.findSchema(u.fieldSchema),d=c.parent.parent["x-component"],f=v({},be(r));return((!l||l==="page")&&d.includes("Form")||!d.includes("Form"))&&delete f.properties.popupClose,i.jsx(e.SchemaSettingsModalItem,{title:r("After successful submission"),initialValues:(x=c==null?void 0:c["x-action-settings"])==null?void 0:x.onSuccess,schema:v({},f),onSubmit:h=>{c["x-action-settings"].onSuccess=h,o.emit("patch",{schema:{"x-uid":c["x-uid"],"x-action-settings":c["x-action-settings"]}})}})}const ge=new e.SchemaSettings({name:"actionSettings:customRequest",items:[{name:"editButton",Component:e.ButtonEditor,useComponentProps(){const{buttonEditorProps:o}=e.useSchemaToolbar();return v({isLink:!0},o)}},{name:"linkageRules",Component:e.SchemaSettingsLinkageRules,useComponentProps(){const{name:o}=e.useCollection(),{linkageRulesProps:r}=e.useSchemaToolbar();return A(v({},r),{collectionName:o,type:"button"})}},{name:"secondConFirm",Component:e.SecondConFirm},{name:"afterSuccessfulSubmission",Component:Ce},{name:"request settings",Component:$},{name:"accessControl",Component:J},{name:"delete",sort:100,Component:e.RemoveButton,useComponentProps(){const{removeButtonProps:o}=e.useSchemaToolbar();return o}}]}),ve=o=>i.jsx(e.SchemaComponentOptions,{scope:{CustomRequestConfigurationFieldsSchema:_},components:{CustomRequestAction:D,CustomRequestInitializer:ye},children:o.children});class X extends e.Plugin{load(){return T(this,null,function*(){this.app.use(ve),this.app.schemaSettingsManager.add(ge),this.app.schemaSettingsManager.add(pe)})}}n.CustomRequestPlugin=X,n.default=X,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/externalVersion.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
"react": "18.3.1",
|
|
3
|
-
"@tachybase/client": "0.
|
|
3
|
+
"@tachybase/client": "1.0.6",
|
|
4
4
|
"react-i18next": "15.2.0",
|
|
5
|
-
"@tachybase/
|
|
6
|
-
"@tachybase/
|
|
7
|
-
"@tachybase/
|
|
8
|
-
"@tachybase/
|
|
9
|
-
"@tachybase/components": "0.
|
|
5
|
+
"@tachybase/logger": "1.0.6",
|
|
6
|
+
"@tachybase/server": "1.0.6",
|
|
7
|
+
"@tachybase/test": "1.0.6",
|
|
8
|
+
"@tachybase/schema": "1.0.6",
|
|
9
|
+
"@tachybase/components": "1.0.6",
|
|
10
10
|
"antd": "5.22.5",
|
|
11
|
-
"@tachybase/utils": "0.
|
|
11
|
+
"@tachybase/utils": "1.0.6",
|
|
12
12
|
"react-router-dom": "6.28.1",
|
|
13
|
-
"@tachybase/actions": "0.
|
|
14
|
-
"@tachybase/evaluators": "0.
|
|
13
|
+
"@tachybase/actions": "1.0.6",
|
|
14
|
+
"@tachybase/evaluators": "1.0.6",
|
|
15
15
|
"axios": "1.7.7",
|
|
16
|
-
"@tachybase/database": "0.
|
|
16
|
+
"@tachybase/database": "1.0.6"
|
|
17
17
|
};
|
package/dist/locale/zh-CN.json
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"Add request header": "添加请求头",
|
|
6
6
|
"Body": "请求体",
|
|
7
7
|
"Custom Request": "自定义请求",
|
|
8
|
+
"Download file name": "下载文件名",
|
|
8
9
|
"Enter description info": "输入描述信息",
|
|
9
10
|
"Format": "格式化",
|
|
10
11
|
"HTTP method": "HTTP 方法",
|
|
@@ -16,6 +17,8 @@
|
|
|
16
17
|
"Parameters": "参数",
|
|
17
18
|
"Please configure the request settings first": "请先配置请求设置",
|
|
18
19
|
"Request settings": "请求设置",
|
|
20
|
+
"Request success": "请求成功",
|
|
21
|
+
"Response body": "响应包体",
|
|
19
22
|
"Roles": "角色",
|
|
20
23
|
"Timeout config": "超时设置",
|
|
21
24
|
"Title": "标题",
|
|
@@ -129,7 +129,8 @@ async function send(ctx, next) {
|
|
|
129
129
|
...currentRecord.data
|
|
130
130
|
},
|
|
131
131
|
currentUser,
|
|
132
|
-
currentTime: (/* @__PURE__ */ new Date()).toISOString()
|
|
132
|
+
currentTime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
133
|
+
$env: ctx.app.environment.getVariables()
|
|
133
134
|
};
|
|
134
135
|
const getParsedValue = (value) => {
|
|
135
136
|
const template = (0, import_utils.parse)(value);
|
|
@@ -163,8 +164,17 @@ async function send(ctx, next) {
|
|
|
163
164
|
);
|
|
164
165
|
try {
|
|
165
166
|
const res = await (0, import_axios.default)({ ...axiosRequestConfig, responseType: "stream" });
|
|
166
|
-
ctx.
|
|
167
|
-
|
|
167
|
+
if (ctx.req.headers["x-response-type"] === "blob") {
|
|
168
|
+
ctx.set("Content-Type", "application/octet-stream");
|
|
169
|
+
} else {
|
|
170
|
+
ctx.set("Content-Type", `${res.headers["content-type"]}`);
|
|
171
|
+
}
|
|
172
|
+
if (res.headers["content-disposition"]) {
|
|
173
|
+
ctx.set("Content-disposition", `${res.headers["content-disposition"]}`);
|
|
174
|
+
} else if (ctx.req.headers["x-response-type"] === "blob") {
|
|
175
|
+
const filename = new URL(requestUrl).pathname.split("/").pop() || "";
|
|
176
|
+
ctx.set("Content-Disposition", `attachment; filename="${filename}"`);
|
|
177
|
+
}
|
|
168
178
|
this.logger.info(`action-custom-request:send:${filterByTk} success`);
|
|
169
179
|
const readable = res.data;
|
|
170
180
|
ctx.body = readable;
|
|
@@ -172,9 +182,7 @@ async function send(ctx, next) {
|
|
|
172
182
|
if (import_axios.default.isAxiosError(err)) {
|
|
173
183
|
ctx.status = ((_c = err.response) == null ? void 0 : _c.status) || 500;
|
|
174
184
|
ctx.body = ((_d = err.response) == null ? void 0 : _d.data) || { message: err.message };
|
|
175
|
-
this.logger.error(
|
|
176
|
-
`action-custom-request:send:${filterByTk} error. status: ${ctx.status}, body: ${typeof ctx.body === "string" ? ctx.body : JSON.stringify(ctx.body)}`
|
|
177
|
-
);
|
|
185
|
+
this.logger.error(`custom-request:send:${filterByTk} error. status: ${ctx.status}, body: `, ctx.body);
|
|
178
186
|
} else {
|
|
179
187
|
this.logger.error(
|
|
180
188
|
`action-custom-request:send:${filterByTk} error. status: ${ctx.status}, message: ${err.message}`
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tachybase/plugin-action-custom-request",
|
|
3
3
|
"displayName": "Action: Custom request",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.6",
|
|
5
5
|
"description": "Sending a request to any HTTP service supports sending context data to the target service.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"Actions"
|
|
@@ -15,19 +15,19 @@
|
|
|
15
15
|
"lodash": "~4.17.21",
|
|
16
16
|
"react-i18next": "^15.2.0",
|
|
17
17
|
"react-router-dom": "6.28.1",
|
|
18
|
-
"@tachybase/components": "0.
|
|
19
|
-
"@tachybase/schema": "0.
|
|
18
|
+
"@tachybase/components": "1.0.6",
|
|
19
|
+
"@tachybase/schema": "1.0.6"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@tachybase/actions": "0.
|
|
23
|
-
"@tachybase/
|
|
24
|
-
"@tachybase/
|
|
25
|
-
"@tachybase/
|
|
26
|
-
"@tachybase/
|
|
27
|
-
"@tachybase/
|
|
28
|
-
"@tachybase/
|
|
29
|
-
"@tachybase/
|
|
30
|
-
"@tachybase/
|
|
22
|
+
"@tachybase/actions": "1.0.6",
|
|
23
|
+
"@tachybase/client": "1.0.6",
|
|
24
|
+
"@tachybase/database": "1.0.6",
|
|
25
|
+
"@tachybase/evaluators": "1.0.6",
|
|
26
|
+
"@tachybase/logger": "1.0.6",
|
|
27
|
+
"@tachybase/sdk": "1.0.6",
|
|
28
|
+
"@tachybase/server": "1.0.6",
|
|
29
|
+
"@tachybase/utils": "1.0.6",
|
|
30
|
+
"@tachybase/test": "1.0.6"
|
|
31
31
|
},
|
|
32
32
|
"description.zh-CN": "向任意 HTTP 服务发送请求,支持将上下文数据发送给目标服务。",
|
|
33
33
|
"displayName.zh-CN": "操作:自定义请求",
|