@tachybase/plugin-action-custom-request 0.23.58 → 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.
@@ -1 +1 @@
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})}},{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"}})});
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"}})});
@@ -1,17 +1,17 @@
1
1
  module.exports = {
2
2
  "react": "18.3.1",
3
- "@tachybase/client": "0.23.58",
3
+ "@tachybase/client": "1.0.6",
4
4
  "react-i18next": "15.2.0",
5
- "@tachybase/logger": "0.23.58",
6
- "@tachybase/server": "0.23.58",
7
- "@tachybase/test": "0.23.58",
8
- "@tachybase/schema": "0.23.58",
9
- "@tachybase/components": "0.23.58",
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.23.58",
11
+ "@tachybase/utils": "1.0.6",
12
12
  "react-router-dom": "6.28.1",
13
- "@tachybase/actions": "0.23.58",
14
- "@tachybase/evaluators": "0.23.58",
13
+ "@tachybase/actions": "1.0.6",
14
+ "@tachybase/evaluators": "1.0.6",
15
15
  "axios": "1.7.7",
16
- "@tachybase/database": "0.23.58"
16
+ "@tachybase/database": "1.0.6"
17
17
  };
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.23.58",
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.23.58",
19
- "@tachybase/schema": "0.23.58"
18
+ "@tachybase/components": "1.0.6",
19
+ "@tachybase/schema": "1.0.6"
20
20
  },
21
21
  "peerDependencies": {
22
- "@tachybase/actions": "0.23.58",
23
- "@tachybase/client": "0.23.58",
24
- "@tachybase/evaluators": "0.23.58",
25
- "@tachybase/logger": "0.23.58",
26
- "@tachybase/server": "0.23.58",
27
- "@tachybase/utils": "0.23.58",
28
- "@tachybase/test": "0.23.58",
29
- "@tachybase/sdk": "0.23.58",
30
- "@tachybase/database": "0.23.58"
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": "操作:自定义请求",