@tachybase/plugin-action-custom-request 1.3.22 → 1.3.24

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,3 +1,4 @@
1
1
  export * from './useCustomizeRequestActionProps';
2
2
  export * from './useGetCustomRequest';
3
3
  export * from './useCustomRequestVariableOptions';
4
+ export * from './useCustomRequestFields';
@@ -0,0 +1 @@
1
+ export declare const useCustomRequestFields: () => (field: any) => void;
@@ -3,3 +3,4 @@ export declare const useCustomRequestVariableOptions: () => {
3
3
  title: string;
4
4
  children: any;
5
5
  }[];
6
+ export declare const useCustomRequestVariableRecordOptions: () => any[];
@@ -0,0 +1 @@
1
+ export declare const useResultValuesVisible: () => boolean;
@@ -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("@tego/client"),require("antd"),require("react-router-dom"),require("react-i18next"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@tachybase/client","@tachybase/schema","@tego/client","antd","react-router-dom","react-i18next","react"],i):(n=typeof globalThis!="undefined"?globalThis:n||self,i(n["@tachybase/plugin-action-custom-request"]={},n.jsxRuntime,n["@tachybase/client"],n["@tachybase/schema"],n["@tego/client"],n.antd,n["react-router-dom"],n["react-i18next"],n.react))})(this,function(n,i,e,p,S,M,B,F,v){"use strict";var Te=Object.defineProperty,Ae=Object.defineProperties;var we=Object.getOwnPropertyDescriptors;var V=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var se=(n,i,e)=>i in n?Te(n,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[i]=e,C=(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},w=(n,i)=>Ae(n,we(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 A=(n,i,e)=>new Promise((p,S)=>{var M=v=>{try{F(e.next(v))}catch(q){S(q)}},B=v=>{try{F(e.throw(v))}catch(q){S(q)}},F=v=>v.done?p(v.value):Promise.resolve(v.value).then(M,B);F((e=e.apply(n,i)).next())});const q="customRequests:listByCurrentRole";var k=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},E={exports:{}},ie=E.exports,H;function ue(){return H||(H=1,function(o,r){(function(u,c){c()})(ie,function(){function u(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 c(s,a,g){var m=new XMLHttpRequest;m.open("GET",s),m.responseType="blob",m.onload=function(){h(m.response,a,g)},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(g){}return 200<=a.status&&299>=a.status}function d(s){try{s.dispatchEvent(new MouseEvent("click"))}catch(g){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 k=="object"&&k.global===k?k:void 0,y=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&&!y?function(s,a,g){var m=f.URL||f.webkitURL,b=document.createElement("a");a=a||s.name||"download",b.download=a,b.rel="noopener",typeof s=="string"?(b.href=s,b.origin===location.origin?d(b):l(b.href)?c(s,a,g):d(b,b.target="_blank")):(b.href=m.createObjectURL(s),setTimeout(function(){m.revokeObjectURL(b.href)},4e4),setTimeout(function(){d(b)},0))}:"msSaveOrOpenBlob"in navigator?function(s,a,g){if(a=a||s.name||"download",typeof s!="string")navigator.msSaveOrOpenBlob(u(s,g),a);else if(l(s))c(s,a,g);else{var m=document.createElement("a");m.href=s,m.target="_blank",setTimeout(function(){d(m)})}}:function(s,a,g,m){if(m=m||open("","_blank"),m&&(m.document.title=m.document.body.innerText="downloading..."),typeof s=="string")return c(s,a,g);var b=s.type==="application/octet-stream",O=/constructor/i.test(f.HTMLElement)||f.safari,P=/CriOS\/[\d]+/.test(navigator.userAgent);if((P||b&&O||y)&&typeof FileReader!="undefined"){var z=new FileReader;z.onloadend=function(){var R=z.result;R=P?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})}(E)),E.exports}var ce=ue();const _="action-custom-request";function x(o){return`{{t('${o}', { ns: '${_}', nsMode: 'fallback' })}}`}function I(){return F.useTranslation(_,{nsMode:"fallback"})}function le(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 me=()=>{const o=e.useAPIClient(),r=B.useNavigate(),u=p.useFieldSchema(),c=e.useCompile(),l=p.useForm(),{getPrimaryKey:d}=e.useCollection_deprecated(),{resource:f,__parent:y,service:h}=e.useBlockRequestContext(),s=e.useRecord(),a=p.useFieldSchema(),g=p.useField(),{setVisible:m}=e.useActionContext(),{modal:b,message:O}=M.App.useApp(),{t:P}=I();return{onClick(){return A(this,null,function*(){var Q,Y,Z,N,ee,te;const{skipValidator:j,onSuccess:t}=(Q=u==null?void 0:u["x-action-settings"])!=null?Q:{},R=u==null?void 0:u["x-action"];j!==!0&&R==="customize:form:request"&&(yield l.submit());let W={};R==="customize:form:request"&&(W=l.values),(Y=g.data)!=null||(g.data={}),g.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"}}),qe=U.headers.getContentType();let oe=le(U.headers["content-disposition"]);if(t!=null&&t.down)if(qe==="application/octet-stream"){const T=t.downTitle;ce.saveAs(U.data,S.parse(T)({filename:oe||""}))}else O.error(P("The current return type is not a document type"));if(g.data.loading=!1,f instanceof e.TableFieldResource||(ee=(N=y==null?void 0:y.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 T=S.parse(t==null?void 0:t.successMessage)({res:U,filename:oe});typeof T!="string"&&(T=JSON.stringify(T)),t!=null&&t.manualClose?b.success({title:c(T),onOk:()=>A(null,null,function*(){t!=null&&t.redirecting&&(t!=null&&t.redirectTo)&&(S.isURL(t.redirectTo)?window.location.href=t.redirectTo:r(t.redirectTo))})}):(O.success(c(T)),t!=null&&t.redirecting&&(t!=null&&t.redirectTo)&&(S.isURL(t.redirectTo)?window.location.href=t.redirectTo:r(t.redirectTo)))}else O.success(P("Request success"))}finally{g.data.loading=!1}})}}},G=()=>{const r=`customRequests:get/${p.useFieldSchema()["x-uid"]}`;return e.useRequest({url:r,params:{appends:["roles"]}},{manual:!0,cacheKey:r})},pe=()=>{const o=e.useCollection_deprecated(),{t:r}=I(),u=e.useCollectionFilterOptions(o),c=e.useCollectionFilterOptions("users"),l=e.useCompile(),[d,f]=v.useMemo(()=>[l(u),l(c)],[u,c]),y=e.useGlobalVariable("$env");return v.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 y&&h.unshift(y),h},[d,f])},L=()=>e.useAPIClient().resource("customRequests"),K={type:"object",properties:{method:{type:"string",required:!0,title:x("HTTP method"),"x-decorator-props":{tooltip:x("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:x("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:x("Headers"),description:x('"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:x("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:x("Add request header"),"x-component":"ArrayItems.Addition"}}},params:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:x("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:x("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:x("Add parameter"),"x-component":"ArrayItems.Addition"}}},data:{type:"string",title:x("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:x("Input request data")},description:x("Only support standard JSON data")},timeout:{type:"number",title:x("Timeout config"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"InputNumber","x-component-props":{addonAfter:x("ms"),min:1,step:1e3,defaultValue:5e3}}}},de={type:"object",properties:{roles:{type:"array",title:x("Roles"),"x-decorator":"FormItem","x-decorator-props":{tooltip:x("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}=I(),{name:r}=e.useCollection_deprecated(),u=p.useFieldSchema(),c=L(),{data:l,refresh:d}=G(),{dn:f}=e.useDesignable(),y=v.useMemo(()=>{var a;const s=C({},(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:S.ArrayItems},beforeOpen:()=>!l&&d(),scope:{useCustomRequestVariableOptions:pe},schema:K,initialValues:y,onSubmit:s=>A(null,null,function*(){const a=ae(s,[]);yield c.updateOrCreate({values:{key:u["x-uid"],options:w(C({},a),{collectionName:r})},filterKeys:["key"]}),f.refresh(),d()})})})}function J(){var y;const{t:o}=I(),r=p.useFieldSchema(),u=L(),{message:c}=M.App.useApp(),{data:l,refresh:d}=G(),{refresh:f}=e.useRequest({url:q},{manual:!0,cacheKey:q});return i.jsx(i.Fragment,{children:i.jsx(e.SchemaSettingsActionModalItem,{title:o("Access control"),schema:de,initialValues:{roles:(y=l==null?void 0:l.data)==null?void 0:y.roles},beforeOpen:()=>!l&&d(),onSubmit:s=>A(null,[s],function*({roles:h}){return yield u.updateOrCreate({values:{key:r["x-uid"],roles:h},filterKeys:["key"]}),d(),f(),c.success(o("Saved successfully"))})})})}const fe=new e.SchemaSettings({name:"CustomRequestActionSettings",items:[w(C({},e.actionSettingsItems[0]),{children:[...e.actionSettingsItems[0].children,{name:"request settings",Component:$},{name:"accessControl",Component:J}]})]}),he=()=>{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"]})}}})},xe=o=>{var d;const u=e.useAPIClient().auth.role==="root",c=p.useFieldSchema(),{data:l}=e.useRequest({url:q},{manual:u,cacheKey:q});return!u&&!((d=l==null?void 0:l.data)!=null&&d.includes(c==null?void 0:c["x-uid"]))?null:o.children},ye={"customize:table:request":e.Action.Link},D=o=>{const u=p.useFieldSchema()["x-action"],c=ye[u]||e.Action;return i.jsx(c,w(C({},o),{useProps:me}))};D.Designer=he,D.Decorator=xe;const ge=o=>{const r=L(),u={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") }}'}}},c=e.useSchemaInitializerItem(),{insert:l}=e.useSchemaInitializer();return i.jsx(e.SchemaInitializerItem,w(C({},c),{onClick:()=>A(null,null,function*(){var f;const d=p.merge(u||{},c.schema||{});(f=c==null?void 0:c.schemaInitialize)==null||f.call(c,d),yield r.create({values:{key:d["x-uid"]}}),l(d)})}))},be=o=>{const{t:r}=I(),{value:u,onChange:c}=o,l=[{value:"res.data",label:r("Response body")},{value:"filename",label:r("Download file name")}];return i.jsx(e.Variable.CodeMirror,{value:u,onChange:c,scope:l,fieldNames:{value:"value",label:"value"}})},ve=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":be,"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 y;const{dn:o}=e.useDesignable(),{t:r}=e.useTranslation(),u=p.useFieldSchema(),c=e.useActionContext(),l=e.findSchema(c.fieldSchema),d=u.parent.parent["x-component"],f=C({},ve(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:(y=u==null?void 0:u["x-action-settings"])==null?void 0:y.onSuccess,schema:C({},f),onSubmit:h=>{u["x-action-settings"].onSuccess=h,o.emit("patch",{schema:{"x-uid":u["x-uid"],"x-action-settings":u["x-action-settings"]}})}})}const Re=new e.SchemaSettings({name:"actionSettings:customRequest",items:[{name:"editButton",Component:e.ButtonEditor,useComponentProps(){const{buttonEditorProps:o}=e.useSchemaToolbar();return C({isLink:!0},o)}},{name:"linkageRules",Component:e.SchemaSettingsLinkageRules,useComponentProps(){const{name:o}=e.useCollection(),{linkageRulesProps:r}=e.useSchemaToolbar();return w(C({},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}}]}),Se=o=>i.jsx(e.SchemaComponentOptions,{scope:{CustomRequestConfigurationFieldsSchema:K},components:{CustomRequestAction:D,CustomRequestInitializer:ge},children:o.children});class X extends e.Plugin{load(){return A(this,null,function*(){this.app.use(Se),this.app.schemaSettingsManager.add(Re),this.app.schemaSettingsManager.add(fe)})}}n.CustomRequestPlugin=X,n.default=X,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(c,p){typeof exports=="object"&&typeof module!="undefined"?p(exports,require("react/jsx-runtime"),require("@tachybase/client"),require("@tachybase/schema"),require("@tego/client"),require("antd"),require("react-router-dom"),require("react-i18next"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@tachybase/client","@tachybase/schema","@tego/client","antd","react-router-dom","react-i18next","react"],p):(c=typeof globalThis!="undefined"?globalThis:c||self,p(c["@tachybase/plugin-action-custom-request"]={},c.jsxRuntime,c["@tachybase/client"],c["@tachybase/schema"],c["@tego/client"],c.antd,c["react-router-dom"],c["react-i18next"],c.react))})(this,function(c,p,e,h,S,V,U,O,b){"use strict";var Ee=Object.defineProperty,ke=Object.defineProperties;var je=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var ue=(c,p,e)=>p in c?Ee(c,p,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[p]=e,C=(c,p)=>{for(var e in p||(p={}))ce.call(p,e)&&ue(c,e,p[e]);if(B)for(var e of B(p))le.call(p,e)&&ue(c,e,p[e]);return c},I=(c,p)=>ke(c,je(p));var me=(c,p)=>{var e={};for(var h in c)ce.call(c,h)&&p.indexOf(h)<0&&(e[h]=c[h]);if(c!=null&&B)for(var h of B(c))p.indexOf(h)<0&&le.call(c,h)&&(e[h]=c[h]);return e};var w=(c,p,e)=>new Promise((h,S)=>{var V=b=>{try{O(e.next(b))}catch(A){S(A)}},U=b=>{try{O(e.throw(b))}catch(A){S(A)}},O=b=>b.done?h(b.value):Promise.resolve(b.value).then(V,U);O((e=e.apply(c,p)).next())});const A="customRequests:listByCurrentRole";var E=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},k={exports:{}},pe=k.exports,H;function de(){return H||(H=1,function(t,a){(function(o,i){i()})(pe,function(){function o(s,m){return typeof m=="undefined"?m={autoBom:!1}:typeof m!="object"&&(console.warn("Deprecated: Expected third argument to be a object"),m={autoBom:!m}),m.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 i(s,m,v){var x=new XMLHttpRequest;x.open("GET",s),x.responseType="blob",x.onload=function(){d(x.response,m,v)},x.onerror=function(){console.error("could not download file")},x.send()}function n(s){var m=new XMLHttpRequest;m.open("HEAD",s,!1);try{m.send()}catch(v){}return 200<=m.status&&299>=m.status}function u(s){try{s.dispatchEvent(new MouseEvent("click"))}catch(v){var m=document.createEvent("MouseEvents");m.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),s.dispatchEvent(m)}}var l=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof E=="object"&&E.global===E?E:void 0,f=l.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),d=l.saveAs||(typeof window!="object"||window!==l?function(){}:"download"in HTMLAnchorElement.prototype&&!f?function(s,m,v){var x=l.URL||l.webkitURL,g=document.createElement("a");m=m||s.name||"download",g.download=m,g.rel="noopener",typeof s=="string"?(g.href=s,g.origin===location.origin?u(g):n(g.href)?i(s,m,v):u(g,g.target="_blank")):(g.href=x.createObjectURL(s),setTimeout(function(){x.revokeObjectURL(g.href)},4e4),setTimeout(function(){u(g)},0))}:"msSaveOrOpenBlob"in navigator?function(s,m,v){if(m=m||s.name||"download",typeof s!="string")navigator.msSaveOrOpenBlob(o(s,v),m);else if(n(s))i(s,m,v);else{var x=document.createElement("a");x.href=s,x.target="_blank",setTimeout(function(){u(x)})}}:function(s,m,v,x){if(x=x||open("","_blank"),x&&(x.document.title=x.document.body.innerText="downloading..."),typeof s=="string")return i(s,m,v);var g=s.type==="application/octet-stream",P=/constructor/i.test(l.HTMLElement)||l.safari,M=/CriOS\/[\d]+/.test(navigator.userAgent);if((M||g&&P||f)&&typeof FileReader!="undefined"){var z=new FileReader;z.onloadend=function(){var R=z.result;R=M?R:R.replace(/^data:[^;]*;/,"data:attachment/file;"),x?x.location.href=R:location=R,x=null},z.readAsDataURL(s)}else{var L=l.URL||l.webkitURL,r=L.createObjectURL(s);x?x.location=r:location.href=r,x=null,setTimeout(function(){L.revokeObjectURL(r)},4e4)}});l.saveAs=d.saveAs=d,t.exports=d})}(k)),k.exports}var fe=de();const G="action-custom-request";function y(t){return`{{t('${t}', { ns: '${G}', nsMode: 'fallback' })}}`}function F(){return O.useTranslation(G,{nsMode:"fallback"})}function xe(t){if(!t)return null;let a=t.match(/filename="([^"]+)"/i);return a?a[1]:(a=t.match(/filename\*=UTF-8''(.+)/i),a?decodeURIComponent(a[1]):null)}const he=(t,a)=>{const o=(u,l)=>l.reduce((f,d)=>f&&f[d]!==void 0?f[d]:void 0,u),i=(u,l)=>typeof u=="string"?u.replace(/\$\{([^}]+)\}/g,(f,d)=>{const s=o(l,d.trim().split("."));return s!==void 0?s:""}).replace(/\{\{([^}]+)\}\}/g,(f,d)=>{const s=o(l,d.trim().split("."));return s!==void 0?s:""}):u;return((u,l)=>u.map(f=>({name:f.name,value:i(f.value,l)})))(t,a)},ye=()=>{const t=e.useAPIClient(),a=U.useNavigate(),o=h.useFieldSchema(),i=e.useCompile(),n=h.useForm(),{getPrimaryKey:u}=e.useCollection_deprecated(),{resource:l,__parent:f,service:d}=e.useBlockRequestContext(),s=e.useRecord(),m=h.useFieldSchema(),v=h.useField(),{setVisible:x}=e.useActionContext(),{modal:g,message:P}=V.App.useApp(),{t:M}=F();return{onClick(){return w(this,null,function*(){var Y,Z,ee,te,oe,N,se,ne;const{skipValidator:L,onSuccess:r}=(Y=o==null?void 0:o["x-action-settings"])!=null?Y:{},{resultValues:R}=(Z=o==null?void 0:o["x-request-setting"])!=null?Z:{},_=o==null?void 0:o["x-action"];L!==!0&&_==="customize:form:request"&&(yield n.submit());let Q={};_==="customize:form:request"&&(Q=n.values),(ee=v.data)!=null||(v.data={}),v.data.loading=!0;try{const T=yield t.request({url:`/customRequests:send/${m["x-uid"]}`,method:"POST",responseType:r!=null&&r.down?"blob":"json",data:{currentRecord:{id:s[u()],appends:(te=d.params[0])==null?void 0:te.appends,data:Q},successMessage:r.successMessage},headers:{"X-Response-Type":r!=null&&r.down?"blob":"json"}}),Ve=T.headers.getContentType();let re=xe(T.headers["content-disposition"]);if(R!=null&&R.length){const q=C(C({},JSON.parse(((oe=T==null?void 0:T.data)==null?void 0:oe.data)||{})),n.values),ae={};he(R,q).forEach(ie=>{ae[ie.name]=ie.value}),n.setValues(ae)}if(r!=null&&r.down)if(Ve==="application/octet-stream"){const q=r.downTitle;fe.saveAs(T.data,S.parse(q)({filename:re||""}))}else P.error(M("The current return type is not a document type"));if(v.data.loading=!1,l instanceof e.TableFieldResource||(se=(N=f==null?void 0:f.service)==null?void 0:N.refresh)==null||se.call(N),(ne=d==null?void 0:d.refresh)==null||ne.call(d),_==="customize:form:request"&&(x==null||x(!1)),r!=null&&r.successMessage){let q=S.parse(r==null?void 0:r.successMessage)({res:T,filename:re});typeof q!="string"&&(q=JSON.stringify(q)),r!=null&&r.manualClose?g.success({title:i(q),onOk:()=>w(null,null,function*(){r!=null&&r.redirecting&&(r!=null&&r.redirectTo)&&(S.isURL(r.redirectTo)?window.location.href=r.redirectTo:a(r.redirectTo))})}):(P.success(i(q)),r!=null&&r.redirecting&&(r!=null&&r.redirectTo)&&(S.isURL(r.redirectTo)?window.location.href=r.redirectTo:a(r.redirectTo)))}else P.success(M("Request success"))}finally{v.data.loading=!1}})}}},K=()=>{const a=`customRequests:get/${h.useFieldSchema()["x-uid"]}`;return e.useRequest({url:a,params:{appends:["roles"]}},{manual:!0,cacheKey:a})},ve=()=>{const t=e.useCollection_deprecated(),{t:a}=F(),o=e.useCollectionFilterOptions(t),i=e.useCollectionFilterOptions("users"),n=e.useCompile(),[u,l]=b.useMemo(()=>[n(o),n(i)],[o,i]),f=e.useGlobalVariable("$env");return b.useMemo(()=>{const d=[{name:"currentRecord",title:a("Current record",{ns:"core"}),children:[...u]},{name:"currentUser",title:a("Current user",{ns:"core"}),children:l},{name:"currentTime",title:a("Current time",{ns:"core"}),children:null}];return f&&d.unshift(f),d},[u,l])},ge=()=>{const t=e.useCollection_deprecated(),{t:a}=F(),o=e.useCollectionFilterOptions(t),i=e.useCollectionFilterOptions("users"),n=e.useCompile(),[u,l]=b.useMemo(()=>[n(o),n(i)],[o,i]),f=e.useGlobalVariable("$env");return b.useMemo(()=>{const d=[...u];return f&&d.unshift(f),d},[u,l])},be=()=>t=>{t.loading=!0;const a=e.useCollection(),o=e.useCompile(),i=["id","createdAt","createdBy","updatedAt","updatedBy"];t.dataSource=a.fields.map(n=>{if(!i.includes(n.name))return{label:o(n.uiSchema.title),value:n.name}}).filter(Boolean),t.loading=!1},j=()=>e.useAPIClient().resource("customRequests"),Ce=()=>{const{fieldSchema:t}=e.useActionContext();return t["x-action"]==="customize:form:request"},$={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}},resultValues:{title:y("Return value setting"),type:"array","x-component":"ArrayItems","x-decorator":"FormItem",items:{type:"object",properties:{space:{type:"void","x-component":"Space",properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Select","x-component-props":{placeholder:y("Name")},"x-reactions":["{{useCustomRequestFields()}}"]},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.TextArea","x-component-props":{scope:"{{useCustomRequestVariableRecordOptions}}"}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:y("Add setting fields"),"x-component":"ArrayItems.Addition"}},"x-visible":"{{useResultValuesVisible()}}"}}},Re={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 J(){var d;const{t}=F(),{name:a}=e.useCollection_deprecated(),o=h.useFieldSchema(),i=j(),{data:n,refresh:u}=K(),{dn:l}=e.useDesignable(),f=b.useMemo(()=>{var m;const s=C({},(m=n==null?void 0:n.data)==null?void 0:m.options);return s.data&&typeof s.data!="string"&&(s.data=JSON.stringify(s.data,null,2)),s},[(d=n==null?void 0:n.data)==null?void 0:d.options]);return p.jsx(p.Fragment,{children:p.jsx(e.SchemaSettingsActionModalItem,{title:t("Request settings"),components:{ArrayItems:S.ArrayItems},beforeOpen:()=>!n&&u(),scope:{useCustomRequestVariableOptions:ve,useCustomRequestFields:be,useCustomRequestVariableRecordOptions:ge,useResultValuesVisible:Ce},schema:$,initialValues:f,onSubmit:s=>w(null,null,function*(){const m=me(s,[]);yield i.updateOrCreate({values:{key:o["x-uid"],options:I(C({},m),{collectionName:a})},filterKeys:["key"]}),o["x-request-setting"]=C({},s),l.emit("patch",{schema:{"x-uid":o["x-uid"],"x-request-setting":o["x-request-setting"]}}),l.refresh(),u()})})})}function X(){var f;const{t}=F(),a=h.useFieldSchema(),o=j(),{message:i}=V.App.useApp(),{data:n,refresh:u}=K(),{refresh:l}=e.useRequest({url:A},{manual:!0,cacheKey:A});return p.jsx(p.Fragment,{children:p.jsx(e.SchemaSettingsActionModalItem,{title:t("Access control"),schema:Re,initialValues:{roles:(f=n==null?void 0:n.data)==null?void 0:f.roles},beforeOpen:()=>!n&&u(),onSubmit:s=>w(null,[s],function*({roles:d}){return yield o.updateOrCreate({values:{key:a["x-uid"],roles:d},filterKeys:["key"]}),u(),l(),i.success(t("Saved successfully"))})})})}const qe=new e.SchemaSettings({name:"CustomRequestActionSettings",items:[I(C({},e.actionSettingsItems[0]),{children:[...e.actionSettingsItems[0].children,{name:"request settings",Component:J},{name:"accessControl",Component:X}]})]}),Se=()=>{const t=j(),a=h.useFieldSchema();return p.jsx(e.Action.Designer,{linkageAction:!0,schemaSettings:"CustomRequestActionSettings",buttonEditorProps:{isLink:a["x-action"]==="customize:table:request"},linkageRulesProps:{type:"button"},removeButtonProps:{onConfirmOk(){return t.destroy({filterByTk:a["x-uid"]})}}})},Ae=t=>{var u;const o=e.useAPIClient().auth.role==="root",i=h.useFieldSchema(),{data:n}=e.useRequest({url:A},{manual:o,cacheKey:A});return!o&&!((u=n==null?void 0:n.data)!=null&&u.includes(i==null?void 0:i["x-uid"]))?null:t.children},Te={"customize:table:request":e.Action.Link},D=t=>{const o=h.useFieldSchema()["x-action"],i=Te[o]||e.Action;return p.jsx(i,I(C({},t),{useProps:ye}))};D.Designer=Se,D.Decorator=Ae;const we=t=>{const a=j(),o={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":h.uid(),"x-action-settings":{onSuccess:{manualClose:!1,redirecting:!1,successMessage:'{{ t("Request success") }}'}}},i=e.useSchemaInitializerItem(),{insert:n}=e.useSchemaInitializer();return p.jsx(e.SchemaInitializerItem,I(C({},i),{onClick:()=>w(null,null,function*(){var l;const u=h.merge(o||{},i.schema||{});(l=i==null?void 0:i.schemaInitialize)==null||l.call(i,u),yield a.create({values:{key:u["x-uid"]}}),n(u)})}))},Fe=t=>{const{t:a}=F(),{value:o,onChange:i}=t,n=[{value:"res.data",label:a("Response body")},{value:"filename",label:a("Download file name")}];return p.jsx(e.Variable.CodeMirror,{value:o,onChange:i,scope:n,fieldNames:{value:"value",label:"value"}})},Ie=t=>({type:"object",title:t("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":Fe,"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 Oe(){var f;const{dn:t}=e.useDesignable(),{t:a}=e.useTranslation(),o=h.useFieldSchema(),i=e.useActionContext(),n=e.findSchema(i.fieldSchema),u=o.parent.parent["x-component"],l=C({},Ie(a));return((!n||n==="page")&&u.includes("Form")||!u.includes("Form"))&&delete l.properties.popupClose,p.jsx(e.SchemaSettingsModalItem,{title:a("After successful submission"),initialValues:(f=o==null?void 0:o["x-action-settings"])==null?void 0:f.onSuccess,schema:C({},l),onSubmit:d=>{o["x-action-settings"].onSuccess=d,t.emit("patch",{schema:{"x-uid":o["x-uid"],"x-action-settings":o["x-action-settings"]}})}})}const Pe=new e.SchemaSettings({name:"actionSettings:customRequest",items:[{name:"editButton",Component:e.ButtonEditor,useComponentProps(){const{buttonEditorProps:t}=e.useSchemaToolbar();return C({isLink:!0},t)}},{name:"linkageRules",Component:e.SchemaSettingsLinkageRules,useComponentProps(){const{name:t}=e.useCollection(),{linkageRulesProps:a}=e.useSchemaToolbar();return I(C({},a),{collectionName:t,type:"button"})}},{name:"secondConFirm",Component:e.SecondConFirm},{name:"afterSuccessfulSubmission",Component:Oe},{name:"request settings",Component:J},{name:"accessControl",Component:X},{name:"delete",sort:100,Component:e.RemoveButton,useComponentProps(){const{removeButtonProps:t}=e.useSchemaToolbar();return t}}]}),Me=t=>p.jsx(e.SchemaComponentOptions,{scope:{CustomRequestConfigurationFieldsSchema:$},components:{CustomRequestAction:D,CustomRequestInitializer:we},children:t.children});class W extends e.Plugin{load(){return w(this,null,function*(){this.app.use(Me),this.app.schemaSettingsManager.add(Pe),this.app.schemaSettingsManager.add(qe)})}}c.CustomRequestPlugin=W,c.default=W,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -171,5 +171,52 @@ export declare const CustomRequestConfigurationFieldsSchema: {
171
171
  defaultValue: number;
172
172
  };
173
173
  };
174
+ resultValues: {
175
+ title: string;
176
+ type: string;
177
+ 'x-component': string;
178
+ 'x-decorator': string;
179
+ items: {
180
+ type: string;
181
+ properties: {
182
+ space: {
183
+ type: string;
184
+ 'x-component': string;
185
+ properties: {
186
+ name: {
187
+ type: string;
188
+ 'x-decorator': string;
189
+ 'x-component': string;
190
+ 'x-component-props': {
191
+ placeholder: string;
192
+ };
193
+ 'x-reactions': string[];
194
+ };
195
+ value: {
196
+ type: string;
197
+ 'x-decorator': string;
198
+ 'x-component': string;
199
+ 'x-component-props': {
200
+ scope: string;
201
+ };
202
+ };
203
+ remove: {
204
+ type: string;
205
+ 'x-decorator': string;
206
+ 'x-component': string;
207
+ };
208
+ };
209
+ };
210
+ };
211
+ };
212
+ properties: {
213
+ add: {
214
+ type: string;
215
+ title: string;
216
+ 'x-component': string;
217
+ };
218
+ };
219
+ 'x-visible': string;
220
+ };
174
221
  };
175
222
  };
@@ -1,11 +1,11 @@
1
1
  module.exports = {
2
2
  "react": "18.3.1",
3
- "@tachybase/client": "1.3.22",
3
+ "@tachybase/client": "1.3.24",
4
4
  "react-i18next": "15.2.0",
5
- "@tego/server": "1.3.39",
6
- "@tachybase/test": "1.3.39",
7
- "@tachybase/schema": "1.3.39",
8
- "@tego/client": "1.3.39",
5
+ "@tego/server": "1.3.49",
6
+ "@tachybase/test": "1.3.49",
7
+ "@tachybase/schema": "1.3.49",
8
+ "@tego/client": "1.3.49",
9
9
  "antd": "5.22.5",
10
10
  "react-router-dom": "6.28.1",
11
11
  "axios": "1.7.7"
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": "1.3.22",
4
+ "version": "1.3.24",
5
5
  "description": "Sending a request to any HTTP service supports sending context data to the target service.",
6
6
  "keywords": [
7
7
  "Actions"
@@ -10,17 +10,17 @@
10
10
  "main": "dist/server/index.js",
11
11
  "dependencies": {},
12
12
  "devDependencies": {
13
- "@tachybase/schema": "^1.3.39",
14
- "@tachybase/test": "^1.3.39",
15
- "@tego/client": "^1.3.39",
16
- "@tego/server": "^1.3.39",
13
+ "@tachybase/schema": "^1.3.49",
14
+ "@tachybase/test": "^1.3.49",
15
+ "@tego/client": "^1.3.49",
16
+ "@tego/server": "^1.3.49",
17
17
  "antd": "5.22.5",
18
18
  "axios": "1.7.7",
19
19
  "file-saver": "^2.0.5",
20
20
  "lodash": "4.17.21",
21
21
  "react-i18next": "15.2.0",
22
22
  "react-router-dom": "6.28.1",
23
- "@tachybase/client": "1.3.22"
23
+ "@tachybase/client": "1.3.24"
24
24
  },
25
25
  "description.zh-CN": "向任意 HTTP 服务发送请求,支持将上下文数据发送给目标服务。",
26
26
  "displayName.zh-CN": "操作:自定义请求",