@nocobase/plugin-action-custom-request 1.3.38-beta → 1.4.0-alpha

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.
@@ -8,8 +8,6 @@
8
8
  */
9
9
  import React from 'react';
10
10
  export declare const CustomRequestActionACLDecorator: (props: any) => any;
11
- export declare const CustomRequestAction: {
12
- (props: any): React.JSX.Element;
13
- Designer: React.FC<{}>;
14
- Decorator: (props: any) => any;
11
+ export declare const CustomRequestAction: React.FC<any> & {
12
+ [key: string]: any;
15
13
  };
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- (function(t,r){typeof exports=="object"&&typeof module!="undefined"?r(exports,require("react/jsx-runtime"),require("@nocobase/client"),require("@formily/react"),require("@nocobase/utils/client"),require("antd"),require("react"),require("react-i18next"),require("@formily/antd-v5"),require("@formily/shared")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@nocobase/client","@formily/react","@nocobase/utils/client","antd","react","react-i18next","@formily/antd-v5","@formily/shared"],r):(t=typeof globalThis!="undefined"?globalThis:t||self,r(t["@nocobase/plugin-action-custom-request"]={},t.jsxRuntime,t["@nocobase/client"],t["@formily/react"],t["@nocobase/utils"],t.antd,t.react,t["react-i18next"],t["@formily/antd-v5"],t["@formily/shared"]))})(this,function(t,r,e,m,F,O,k,P,R,g){"use strict";var de=Object.defineProperty,fe=Object.defineProperties;var he=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var Y=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var X=(t,r,e)=>r in t?de(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,A=(t,r)=>{for(var e in r||(r={}))Y.call(r,e)&&X(t,e,r[e]);if(U)for(var e of U(r))Q.call(r,e)&&X(t,e,r[e]);return t},I=(t,r)=>fe(t,he(r));var Z=(t,r)=>{var e={};for(var m in t)Y.call(t,m)&&r.indexOf(m)<0&&(e[m]=t[m]);if(t!=null&&U)for(var m of U(t))r.indexOf(m)<0&&Q.call(t,m)&&(e[m]=t[m]);return e};var q=(t,r,e)=>new Promise((m,F)=>{var O=R=>{try{P(e.next(R))}catch(g){F(g)}},k=R=>{try{P(e.throw(R))}catch(g){F(g)}},P=R=>R.done?m(R.value):Promise.resolve(R.value).then(O,k);P((e=e.apply(t,r)).next())});const L="customRequests:listByCurrentRole";var E=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},V={exports:{}};(function(s,p){(function(i,c){c()})(E,function(){function i(o,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(o.type)?new Blob(["\uFEFF",o],{type:o.type}):o}function c(o,a,y){var l=new XMLHttpRequest;l.open("GET",o),l.responseType="blob",l.onload=function(){v(l.response,a,y)},l.onerror=function(){console.error("could not download file")},l.send()}function d(o){var a=new XMLHttpRequest;a.open("HEAD",o,!1);try{a.send()}catch(y){}return 200<=a.status&&299>=a.status}function f(o){try{o.dispatchEvent(new MouseEvent("click"))}catch(y){var a=document.createEvent("MouseEvents");a.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),o.dispatchEvent(a)}}var u=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof E=="object"&&E.global===E?E:void 0,x=u.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),v=u.saveAs||(typeof window!="object"||window!==u?function(){}:"download"in HTMLAnchorElement.prototype&&!x?function(o,a,y){var l=u.URL||u.webkitURL,C=document.createElement("a");a=a||o.name||"download",C.download=a,C.rel="noopener",typeof o=="string"?(C.href=o,C.origin===location.origin?f(C):d(C.href)?c(o,a,y):f(C,C.target="_blank")):(C.href=l.createObjectURL(o),setTimeout(function(){l.revokeObjectURL(C.href)},4e4),setTimeout(function(){f(C)},0))}:"msSaveOrOpenBlob"in navigator?function(o,a,y){if(a=a||o.name||"download",typeof o!="string")navigator.msSaveOrOpenBlob(i(o,y),a);else if(d(o))c(o,a,y);else{var l=document.createElement("a");l.href=o,l.target="_blank",setTimeout(function(){f(l)})}}:function(o,a,y,l){if(l=l||open("","_blank"),l&&(l.document.title=l.document.body.innerText="downloading..."),typeof o=="string")return c(o,a,y);var C=o.type==="application/octet-stream",b=/constructor/i.test(u.HTMLElement)||u.safari,M=/CriOS\/[\d]+/.test(navigator.userAgent);if((M||C&&b||x)&&typeof FileReader!="undefined"){var n=new FileReader;n.onloadend=function(){var S=n.result;S=M?S:S.replace(/^data:[^;]*;/,"data:attachment/file;"),l?l.location.href=S:location=S,l=null},n.readAsDataURL(o)}else{var T=u.URL||u.webkitURL,w=T.createObjectURL(o);l?l.location=w:location.href=w,l=null,setTimeout(function(){T.revokeObjectURL(w)},4e4)}});u.saveAs=v.saveAs=v,s.exports=v})})(V);var ee=V.exports;const te=()=>{const s=e.useAPIClient(),p=e.useNavigateNoUpdate(),i=m.useFieldSchema(),c=e.useCompile(),d=m.useForm(),f=e.useRecord(),u=m.useFieldSchema(),x=m.useField(),{setVisible:v}=e.useActionContext(),{modal:o,message:a}=O.App.useApp(),y=e.useDataSourceKey();return{onClick(C,b){return q(this,null,function*(){var S,$;const{skipValidator:M,onSuccess:n}=(S=i==null?void 0:i["x-action-settings"])!=null?S:{},T=i==null?void 0:i["x-action"];M!==!0&&T==="customize:form:request"&&(yield d.submit());let w=A({},f);T==="customize:form:request"&&(w=d.values),($=x.data)!=null||(x.data={}),x.data.loading=!0;try{const z=yield s.request({url:`/customRequests:send/${u["x-uid"]}`,method:"POST",data:{currentRecord:{dataSourceKey:y,data:w}},responseType:u["x-response-type"]==="stream"?"blob":"json"});if(z.headers["content-disposition"]){const pe=/attachment;\s*filename="([^"]+)"/,W=z.headers["content-disposition"].match(pe);W[1]&&ee.saveAs(z.data,W[1])}if(x.data.loading=!1,b&&(b==null||b()),T==="customize:form:request"&&(v==null||v(!1)),!(n!=null&&n.successMessage))return;n!=null&&n.manualClose?o.success({title:c(n==null?void 0:n.successMessage),onOk:()=>q(this,null,function*(){n!=null&&n.redirecting&&(n!=null&&n.redirectTo)&&(F.isURL(n.redirectTo)?window.location.href=n.redirectTo:p(n.redirectTo))})}):(a.success(c(n==null?void 0:n.successMessage)),n!=null&&n.redirecting&&(n!=null&&n.redirectTo)&&(F.isURL(n.redirectTo)?window.location.href=n.redirectTo:p(n.redirectTo)))}finally{x.data.loading=!1}})}}},_=()=>{const p=`customRequests:get/${m.useFieldSchema()["x-uid"]}`;return e.useRequest({url:p,params:{appends:["roles"]}},{manual:!0,cacheKey:p})},K="action-custom-request";function h(s){return`{{t('${s}', { ns: '${K}', nsMode: 'fallback' })}}`}function D(){return P.useTranslation(K,{nsMode:"fallback"})}const oe=()=>{const s=e.useCollection_deprecated(),{t:p}=D(),i=e.useCollectionFilterOptions(s),c=e.useCollectionFilterOptions("users",e.DEFAULT_DATA_SOURCE_KEY),d=e.useCompile(),[f,u]=k.useMemo(()=>[d(i),d(c)],[i,c]);return k.useMemo(()=>[{name:"currentRecord",title:p("Current record",{ns:"client"}),children:[...f]},{name:"currentUser",title:p("Current user",{ns:"client"}),children:u},{name:"currentTime",title:p("Current time",{ns:"client"}),children:null},{name:"$nToken",title:"API token",children:null}],[f,u])},j=()=>e.useAPIClient().resource("customRequests"),B={type:"object",properties:{method:{type:"string",required:!0,title:h("HTTP method"),"x-decorator-props":{tooltip:h("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:h("URL"),"x-decorator":"FormItem","x-component":"Variable.RawTextArea","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",autoSize:!0,fieldNames:{value:"name",label:"title"},placeholder:"https://www.nocobase.com"}},headers:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:h("Headers"),description:h('"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:h("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:h("Add request header"),"x-component":"ArrayItems.Addition"}}},params:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:h("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:h("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:h("Add parameter"),"x-component":"ArrayItems.Addition"}}},data:{type:"string",title:h("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:h("Input request data")},description:h("Only support standard JSON data")},timeout:{type:"number",title:h("Timeout config"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"InputNumber","x-component-props":{addonAfter:h("ms"),min:1,step:1e3,defaultValue:5e3}},responseType:{type:"string",title:h("Response type"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"Select",default:"json",enum:[{value:"json",label:"JSON"},{value:"stream",label:"Stream"}]}}},se={type:"object",properties:{roles:{type:"array",title:h("Roles"),"x-decorator":"FormItem","x-decorator-props":{tooltip:h("If not set, all roles can see this action")},"x-component":"RemoteSelect","x-component-props":{multiple:!0,objectValue:!0,dataSource:e.DEFAULT_DATA_SOURCE_KEY,service:{resource:"roles"},manual:!1,fieldNames:{label:"title",value:"name"}}}}};function H(){var o;const{t:s}=D(),{name:p}=e.useCollection_deprecated(),i=e.useDataSourceKey(),c=m.useFieldSchema(),d=j(),{message:f}=O.App.useApp(),{data:u,refresh:x}=_(),{dn:v}=e.useDesignable();return r.jsx(r.Fragment,{children:r.jsx(e.SchemaSettingsActionModalItem,{title:s("Request settings"),components:{ArrayItems:R.ArrayItems},beforeOpen:()=>!u&&x(),scope:{useCustomRequestVariableOptions:oe},schema:B,initialValues:A({},(o=u==null?void 0:u.data)==null?void 0:o.options),onSubmit:a=>q(this,null,function*(){const y=Z(a,[]);c["x-response-type"]=y.responseType,yield d.updateOrCreate({values:{key:c["x-uid"],options:I(A({},y),{collectionName:p,dataSourceKey:i})},filterKeys:["key"]}),v.emit("patch",{schema:{"x-response-type":y.responseType,"x-uid":c["x-uid"]}}),x(),f.success(s("Saved successfully"))})})})}function G(){var x;const{t:s}=D(),p=m.useFieldSchema(),i=j(),{message:c}=O.App.useApp(),{data:d,refresh:f}=_(),{refresh:u}=e.useRequest({url:L},{manual:!0,cacheKey:L});return r.jsx(r.Fragment,{children:r.jsx(e.SchemaSettingsActionModalItem,{title:s("Access control"),schema:se,initialValues:{roles:(x=d==null?void 0:d.data)==null?void 0:x.roles},beforeOpen:()=>!d&&f(),onSubmit:o=>q(this,[o],function*({roles:v}){return yield i.updateOrCreate({values:{key:p["x-uid"],roles:v},filterKeys:["key"]}),f(),u(),c.success(s("Saved successfully"))})})})}const ne=new e.SchemaSettings({name:"CustomRequestActionSettings",items:[I(A({},e.actionSettingsItems[0]),{children:[...e.actionSettingsItems[0].children,{name:"request settings",Component:H},{name:"accessControl",Component:G}]})]}),re=()=>{const s=j(),p=m.useFieldSchema();return r.jsx(e.Action.Designer,{linkageAction:!0,schemaSettings:"CustomRequestActionSettings",buttonEditorProps:{isLink:p["x-action"]==="customize:table:request"},linkageRulesProps:{type:"button"},removeButtonProps:{onConfirmOk(){return s.destroy({filterByTk:p["x-uid"]})}}})},ae=s=>{var f;const i=e.useAPIClient().auth.role==="root",c=m.useFieldSchema(),{data:d}=e.useRequest({url:L},{manual:i,cacheKey:L});return!i&&!((f=d==null?void 0:d.data)!=null&&f.includes(c==null?void 0:c["x-uid"]))?null:s.children},ie={"customize:table:request":e.Action.Link},N=s=>{const i=m.useFieldSchema()["x-action"],c=ie[i]||e.Action;return r.jsx(c,I(A({},s),{useProps:te}))};N.Designer=re,N.Decorator=ae;const ue=()=>({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":g.uid(),"x-action-settings":{onSuccess:{manualClose:!1,redirecting:!1,successMessage:'{{t("Request success")}}'}}}),ce=s=>{const p=j(),i=e.useSchemaInitializerItem(),{insert:c}=e.useSchemaInitializer(),d=ue();return r.jsx(e.SchemaInitializerItem,I(A({},i),{onClick:()=>q(this,null,function*(){var u;const f=g.merge(d||{},i.schema||{});(u=i==null?void 0:i.schemaInitialize)==null||u.call(i,f),c(f),yield p.create({values:{key:f["x-uid"]}})})}))},le=new e.SchemaSettings({name:"actionSettings:customRequest",items:[{name:"editButton",Component:e.ButtonEditor,useComponentProps(){return{isLink:m.useFieldSchema()["x-action"]==="customize:table:request"}}},{name:"linkageRules",Component:e.SchemaSettingsLinkageRules,useComponentProps(){const{name:s}=e.useCollection(),{linkageRulesProps:p}=e.useSchemaToolbar();return I(A({},p),{collectionName:s})},useVisible(){const s=e.useCollectionRecord();return!(s!=null&&s.isNew)}},{name:"secondConFirm",Component:e.SecondConFirm},{name:"afterSuccessfulSubmission",Component:e.AfterSuccess},{name:"request settings",Component:H},{name:"accessControl",Component:G},{name:"refreshDataBlockRequest",Component:e.RefreshDataBlockRequest,useComponentProps(){return{isPopupAction:!1}}},{name:"delete",sort:100,Component:e.RemoveButton,useComponentProps(){const{removeButtonProps:s}=e.useSchemaToolbar();return s}}]}),me=s=>r.jsx(e.SchemaComponentOptions,{scope:{CustomRequestConfigurationFieldsSchema:B},components:{CustomRequestAction:N,CustomRequestInitializer:ce},children:s.children});class J extends e.Plugin{load(){return q(this,null,function*(){this.app.use(me),this.app.schemaSettingsManager.add(le),this.app.schemaSettingsManager.add(ne)})}}t.PluginActionCustomRequestClient=J,t.default=J,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
10
+ (function(o,n){typeof exports=="object"&&typeof module!="undefined"?n(exports,require("react/jsx-runtime"),require("@nocobase/client"),require("@formily/react"),require("@nocobase/utils/client"),require("antd"),require("react"),require("react-i18next"),require("@formily/antd-v5"),require("@formily/shared")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@nocobase/client","@formily/react","@nocobase/utils/client","antd","react","react-i18next","@formily/antd-v5","@formily/shared"],n):(o=typeof globalThis!="undefined"?globalThis:o||self,n(o["@nocobase/plugin-action-custom-request"]={},o.jsxRuntime,o["@nocobase/client"],o["@formily/react"],o["@nocobase/utils"],o.antd,o.react,o["react-i18next"],o["@formily/antd-v5"],o["@formily/shared"]))})(this,function(o,n,e,m,b,F,L,P,v,w){"use strict";var ve=Object.defineProperty,Ae=Object.defineProperties;var Re=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var se=(o,n,e)=>n in o?ve(o,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[n]=e,g=(o,n)=>{for(var e in n||(n={}))ne.call(n,e)&&se(o,e,n[e]);if(N)for(var e of N(n))re.call(n,e)&&se(o,e,n[e]);return o},I=(o,n)=>Ae(o,Re(n));var ae=(o,n)=>{var e={};for(var m in o)ne.call(o,m)&&n.indexOf(m)<0&&(e[m]=o[m]);if(o!=null&&N)for(var m of N(o))n.indexOf(m)<0&&re.call(o,m)&&(e[m]=o[m]);return e};var q=(o,n,e)=>new Promise((m,b)=>{var F=v=>{try{P(e.next(v))}catch(w){b(w)}},L=v=>{try{P(e.throw(v))}catch(w){b(w)}},P=v=>v.done?m(v.value):Promise.resolve(v.value).then(F,L);P((e=e.apply(o,n)).next())});const k="customRequests:listByCurrentRole";var E=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},H={exports:{}};(function(t,c){(function(a,u){u()})(E,function(){function a(s,r){return typeof r=="undefined"?r={autoBom:!1}:typeof r!="object"&&(console.warn("Deprecated: Expected third argument to be a object"),r={autoBom:!r}),r.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,r,x){var l=new XMLHttpRequest;l.open("GET",s),l.responseType="blob",l.onload=function(){C(l.response,r,x)},l.onerror=function(){console.error("could not download file")},l.send()}function p(s){var r=new XMLHttpRequest;r.open("HEAD",s,!1);try{r.send()}catch(x){}return 200<=r.status&&299>=r.status}function d(s){try{s.dispatchEvent(new MouseEvent("click"))}catch(x){var r=document.createEvent("MouseEvents");r.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),s.dispatchEvent(r)}}var i=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof E=="object"&&E.global===E?E:void 0,h=i.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),C=i.saveAs||(typeof window!="object"||window!==i?function(){}:"download"in HTMLAnchorElement.prototype&&!h?function(s,r,x){var l=i.URL||i.webkitURL,S=document.createElement("a");r=r||s.name||"download",S.download=r,S.rel="noopener",typeof s=="string"?(S.href=s,S.origin===location.origin?d(S):p(S.href)?u(s,r,x):d(S,S.target="_blank")):(S.href=l.createObjectURL(s),setTimeout(function(){l.revokeObjectURL(S.href)},4e4),setTimeout(function(){d(S)},0))}:"msSaveOrOpenBlob"in navigator?function(s,r,x){if(r=r||s.name||"download",typeof s!="string")navigator.msSaveOrOpenBlob(a(s,x),r);else if(p(s))u(s,r,x);else{var l=document.createElement("a");l.href=s,l.target="_blank",setTimeout(function(){d(l)})}}:function(s,r,x,l){if(l=l||open("","_blank"),l&&(l.document.title=l.document.body.innerText="downloading..."),typeof s=="string")return u(s,r,x);var S=s.type==="application/octet-stream",T=/constructor/i.test(i.HTMLElement)||i.safari,D=/CriOS\/[\d]+/.test(navigator.userAgent);if((D||S&&T||h)&&typeof FileReader!="undefined"){var O=new FileReader;O.onloadend=function(){var y=O.result;y=D?y:y.replace(/^data:[^;]*;/,"data:attachment/file;"),l?l.location.href=y:location=y,l=null},O.readAsDataURL(s)}else{var U=i.URL||i.webkitURL,A=U.createObjectURL(s);l?l.location=A:location.href=A,l=null,setTimeout(function(){U.revokeObjectURL(A)},4e4)}});i.saveAs=C.saveAs=C,t.exports=C})})(H);var ie=H.exports;const ce=()=>{const t=e.useAPIClient(),c=e.useNavigateNoUpdate(),a=m.useFieldSchema(),u=e.useCompile(),p=m.useForm(),d=e.useRecord(),i=m.useFieldSchema(),h=m.useField(),{setVisible:C}=e.useActionContext(),{modal:s,message:r}=F.App.useApp(),x=e.useDataSourceKey();return{onClick(S,T){return q(this,null,function*(){var te,oe;const{skipValidator:D,onSuccess:O}=(te=a==null?void 0:a["x-action-settings"])!=null?te:{},{manualClose:U,redirecting:A,redirectTo:y,successMessage:B,actionAfterSuccess:R}=O||{},Z=a==null?void 0:a["x-action"];D!==!0&&Z==="customize:form:request"&&(yield p.submit());let ee=g({},d);Z==="customize:form:request"&&(ee=p.values),(oe=h.data)!=null||(h.data={}),h.data.loading=!0;try{const K=yield t.request({url:`/customRequests:send/${i["x-uid"]}`,method:"POST",data:{currentRecord:{dataSourceKey:x,data:ee}},responseType:i["x-response-type"]==="stream"?"blob":"json"});if(K.headers["content-disposition"]){const Ce=/attachment;\s*filename="([^"]+)"/,M=K.headers["content-disposition"].match(Ce);M!=null&&M[1]&&ie.saveAs(K.data,M[1])}if(h.data.loading=!1,T&&(T==null||T()),(R==="previous"||!R&&A!==!0)&&(C==null||C(!1)),!B){(A&&!R||R==="redirect")&&y&&(b.isURL(y)?window.location.href=y:c(y));return}U?s.success({title:u(B),onOk:()=>q(this,null,function*(){(A&&!R||R==="redirect")&&y&&(b.isURL(y)?window.location.href=y:c(y))})}):(r.success(u(B)),(A&&!R||R==="redirect")&&y&&(b.isURL(y)?window.location.href=y:c(y)))}finally{h.data.loading=!1}})}}},G=()=>{const c=`customRequests:get/${m.useFieldSchema()["x-uid"]}`;return e.useRequest({url:c,params:{appends:["roles"]}},{manual:!0,cacheKey:c})},J="action-custom-request";function f(t){return`{{t('${t}', { ns: '${J}', nsMode: 'fallback' })}}`}function _(){return P.useTranslation(J,{nsMode:"fallback"})}const W=()=>{const t=e.useCollection_deprecated(),{t:c}=_(),a=e.useCollectionFilterOptions(t),u=e.useCollectionFilterOptions("users",e.DEFAULT_DATA_SOURCE_KEY),p=e.useCompile(),d=e.useCollectionRecordData(),[i,h]=L.useMemo(()=>[p(a),p(u)],[a,u]);return L.useMemo(()=>[d&&{name:"currentRecord",title:c("Current record",{ns:"client"}),children:[...i]},{name:"currentUser",title:c("Current user",{ns:"client"}),children:h},{name:"currentTime",title:c("Current time",{ns:"client"}),children:null},{name:"$nToken",title:"API token",children:null}].filter(Boolean),[d,c,i,h])},j=()=>e.useAPIClient().resource("customRequests"),ue={value:"name",label:"title"},z=()=>({scope:W(),fieldNames:ue,useTypedConstant:!0}),X={type:"object",properties:{method:{type:"string",required:!0,title:f("HTTP method"),"x-decorator-props":{tooltip:f("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:f("URL"),"x-decorator":"FormItem","x-component":"Variable.TextArea","x-use-component-props":z,"x-component-props":{placeholder:"https://www.nocobase.com"}},headers:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:f("Headers"),description:f('"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:f("Name")}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.TextArea","x-use-component-props":z},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:f("Add request header"),"x-component":"ArrayItems.Addition"}}},params:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:f("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:f("Name")}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.TextArea","x-use-component-props":z},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:f("Add parameter"),"x-component":"ArrayItems.Addition"}}},data:{type:"string",title:f("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:f("Input request data")},description:f("Only support standard JSON data")},timeout:{type:"number",title:f("Timeout config"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"InputNumber","x-component-props":{addonAfter:f("ms"),min:1,step:1e3,defaultValue:5e3}},responseType:{type:"string",title:f("Response type"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"Select",default:"json",enum:[{value:"json",label:"JSON"},{value:"stream",label:"Stream"}]}}},le={type:"object",properties:{roles:{type:"array",title:f("Roles"),"x-decorator":"FormItem","x-decorator-props":{tooltip:f("If not set, all roles can see this action")},"x-component":"RemoteSelect","x-component-props":{multiple:!0,objectValue:!0,dataSource:e.DEFAULT_DATA_SOURCE_KEY,service:{resource:"roles"},manual:!1,fieldNames:{label:"title",value:"name"}}}}};function Y(){var s;const{t}=_(),{name:c}=e.useCollection_deprecated(),a=e.useDataSourceKey(),u=m.useFieldSchema(),p=j(),{message:d}=F.App.useApp(),{data:i,refresh:h}=G(),{dn:C}=e.useDesignable();return n.jsx(n.Fragment,{children:n.jsx(e.SchemaSettingsActionModalItem,{title:t("Request settings"),components:{ArrayItems:v.ArrayItems},beforeOpen:()=>!i&&h(),scope:{useCustomRequestVariableOptions:W},schema:X,initialValues:g({},(s=i==null?void 0:i.data)==null?void 0:s.options),onSubmit:r=>q(this,null,function*(){const x=ae(r,[]);u["x-response-type"]=x.responseType,yield p.updateOrCreate({values:{key:u["x-uid"],options:I(g({},x),{collectionName:c,dataSourceKey:a})},filterKeys:["key"]}),C.emit("patch",{schema:{"x-response-type":x.responseType,"x-uid":u["x-uid"]}}),h(),d.success(t("Saved successfully"))})})})}function $(){var h;const{t}=_(),c=m.useFieldSchema(),a=j(),{message:u}=F.App.useApp(),{data:p,refresh:d}=G(),{refresh:i}=e.useRequest({url:k},{manual:!0,cacheKey:k});return n.jsx(n.Fragment,{children:n.jsx(e.SchemaSettingsActionModalItem,{title:t("Access control"),schema:le,initialValues:{roles:(h=p==null?void 0:p.data)==null?void 0:h.roles},beforeOpen:()=>!p&&d(),onSubmit:s=>q(this,[s],function*({roles:C}){return yield a.updateOrCreate({values:{key:c["x-uid"],roles:C},filterKeys:["key"]}),d(),i(),u.success(t("Saved successfully"))})})})}const me=new e.SchemaSettings({name:"CustomRequestActionSettings",items:[I(g({},e.actionSettingsItems[0]),{children:[...e.actionSettingsItems[0].children,{name:"request settings",Component:Y},{name:"accessControl",Component:$}]})]}),pe=()=>{const t=j(),c=m.useFieldSchema();return n.jsx(e.Action.Designer,{linkageAction:!0,schemaSettings:"CustomRequestActionSettings",buttonEditorProps:{isLink:c["x-action"]==="customize:table:request"},linkageRulesProps:{type:"button"},removeButtonProps:{onConfirmOk(){return t.destroy({filterByTk:c["x-uid"]})}}})},de=t=>{var d;const a=e.useAPIClient().auth.role==="root",u=m.useFieldSchema(),{data:p}=e.useRequest({url:k},{manual:a,cacheKey:k});return!a&&!((d=p==null?void 0:p.data)!=null&&d.includes(u==null?void 0:u["x-uid"]))?null:t.children},fe={"customize:table:request":e.Action.Link},V=e.withDynamicSchemaProps(t=>{const a=m.useFieldSchema()["x-action"],u=fe[a]||e.Action;return n.jsx(u,I(g({},t),{useProps:ce}))});V.Designer=pe,V.Decorator=de;const he=()=>({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":w.uid(),"x-action-settings":{onSuccess:{manualClose:!1,redirecting:!1,successMessage:'{{t("Request success")}}'}}}),ye=t=>{const c=j(),a=e.useSchemaInitializerItem(),{insert:u}=e.useSchemaInitializer(),p=he();return n.jsx(e.SchemaInitializerItem,I(g({},a),{onClick:()=>q(this,null,function*(){var i;const d=w.merge(p||{},a.schema||{});(i=a==null?void 0:a.schemaInitialize)==null||i.call(a,d),u(d),yield c.create({values:{key:d["x-uid"]}})})}))},xe=new e.SchemaSettings({name:"actionSettings:customRequest",items:[{name:"editButton",Component:e.ButtonEditor,useComponentProps(){return{isLink:m.useFieldSchema()["x-action"]==="customize:table:request"}}},{name:"linkageRules",Component:e.SchemaSettingsLinkageRules,useComponentProps(){const{name:t}=e.useCollection()||{},{linkageRulesProps:c}=e.useSchemaToolbar();return I(g({},c),{collectionName:t})},useVisible(){const t=e.useCollectionRecord();return t&&t.data&&!(t!=null&&t.isNew)}},{name:"secondConFirm",Component:e.SecondConFirm},{name:"afterSuccessfulSubmission",Component:e.AfterSuccess},{name:"request settings",Component:Y},{name:"accessControl",Component:$},{name:"refreshDataBlockRequest",Component:e.RefreshDataBlockRequest,useComponentProps(){return{isPopupAction:!1}},useVisible(){return!!e.useCollection()}},{name:"delete",sort:100,Component:e.RemoveButton,useComponentProps(){const{removeButtonProps:t}=e.useSchemaToolbar();return t}}]}),Se=t=>n.jsx(e.SchemaComponentOptions,{scope:{CustomRequestConfigurationFieldsSchema:X},components:{CustomRequestAction:V,CustomRequestInitializer:ye},children:t.children});class Q extends e.Plugin{load(){return q(this,null,function*(){this.app.use(Se),this.app.schemaSettingsManager.add(xe),this.app.schemaSettingsManager.add(me)})}}o.PluginActionCustomRequestClient=Q,o.default=Q,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -35,13 +35,19 @@ export declare const CustomRequestConfigurationFieldsSchema: {
35
35
  title: string;
36
36
  'x-decorator': string;
37
37
  'x-component': string;
38
- 'x-component-props': {
39
- scope: string;
40
- autoSize: boolean;
38
+ 'x-use-component-props': () => {
39
+ scope: {
40
+ name: string;
41
+ title: string;
42
+ children: any;
43
+ }[];
41
44
  fieldNames: {
42
45
  value: string;
43
46
  label: string;
44
47
  };
48
+ useTypedConstant: boolean;
49
+ };
50
+ 'x-component-props': {
45
51
  placeholder: string;
46
52
  };
47
53
  };
@@ -70,8 +76,12 @@ export declare const CustomRequestConfigurationFieldsSchema: {
70
76
  type: string;
71
77
  'x-decorator': string;
72
78
  'x-component': string;
73
- 'x-component-props': {
74
- scope: string;
79
+ 'x-use-component-props': () => {
80
+ scope: {
81
+ name: string;
82
+ title: string;
83
+ children: any;
84
+ }[];
75
85
  fieldNames: {
76
86
  value: string;
77
87
  label: string;
@@ -120,8 +130,12 @@ export declare const CustomRequestConfigurationFieldsSchema: {
120
130
  type: string;
121
131
  'x-decorator': string;
122
132
  'x-component': string;
123
- 'x-component-props': {
124
- scope: string;
133
+ 'x-use-component-props': () => {
134
+ scope: {
135
+ name: string;
136
+ title: string;
137
+ children: any;
138
+ }[];
125
139
  fieldNames: {
126
140
  value: string;
127
141
  label: string;
@@ -8,19 +8,19 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.3.38-beta",
11
+ "@nocobase/client": "1.4.0-alpha",
12
12
  "react": "18.2.0",
13
13
  "react-i18next": "11.18.6",
14
14
  "@formily/react": "2.3.0",
15
- "@nocobase/logger": "1.3.38-beta",
16
- "@nocobase/server": "1.3.38-beta",
17
- "@nocobase/test": "1.3.38-beta",
15
+ "@nocobase/logger": "1.4.0-alpha",
16
+ "@nocobase/server": "1.4.0-alpha",
17
+ "@nocobase/test": "1.4.0-alpha",
18
18
  "@formily/antd-v5": "1.1.9",
19
19
  "antd": "5.12.8",
20
- "@nocobase/utils": "1.3.38-beta",
20
+ "@nocobase/utils": "1.4.0-alpha",
21
21
  "@formily/shared": "2.3.0",
22
- "@nocobase/actions": "1.3.38-beta",
23
- "@nocobase/evaluators": "1.3.38-beta",
24
- "axios": "0.26.1",
25
- "@nocobase/database": "1.3.38-beta"
22
+ "@nocobase/actions": "1.4.0-alpha",
23
+ "@nocobase/evaluators": "1.4.0-alpha",
24
+ "axios": "1.7.7",
25
+ "@nocobase/database": "1.4.0-alpha"
26
26
  };
@@ -8,4 +8,5 @@
8
8
  */
9
9
  import { Context, Next } from '@nocobase/actions';
10
10
  import CustomRequestPlugin from '../plugin';
11
+ export declare const getParsedValue: (value: any, variables: any) => any;
11
12
  export declare function send(this: CustomRequestPlugin, ctx: Context, next: Next): Promise<any>;
@@ -36,6 +36,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
36
36
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
37
  var send_exports = {};
38
38
  __export(send_exports, {
39
+ getParsedValue: () => getParsedValue,
39
40
  send: () => send
40
41
  });
41
42
  module.exports = __toCommonJS(send_exports);
@@ -75,6 +76,13 @@ const getCurrentUserAppends = (str, user) => {
75
76
  }
76
77
  }).filter(Boolean);
77
78
  };
79
+ const getParsedValue = (value, variables) => {
80
+ const template = (0, import_utils.parse)(value);
81
+ template.parameters.forEach(({ key }) => {
82
+ (0, import_evaluators.appendArrayColumn)(variables, key);
83
+ });
84
+ return template(variables);
85
+ };
78
86
  async function send(ctx, next) {
79
87
  var _a, _b, _c, _d;
80
88
  const resourceName = ctx.action.resourceName;
@@ -151,24 +159,17 @@ async function send(ctx, next) {
151
159
  currentTime: (/* @__PURE__ */ new Date()).toISOString(),
152
160
  $nToken: ctx.getBearerToken()
153
161
  };
154
- const getParsedValue = (value) => {
155
- const template = (0, import_utils.parse)(value);
156
- template.parameters.forEach(({ key }) => {
157
- (0, import_evaluators.appendArrayColumn)(variables, key);
158
- });
159
- return template(variables);
160
- };
161
162
  const axiosRequestConfig = {
162
163
  baseURL: ctx.origin,
163
164
  ...options,
164
- url: getParsedValue(url),
165
+ url: getParsedValue(url, variables),
165
166
  headers: {
166
167
  Authorization: "Bearer " + ctx.getBearerToken(),
167
168
  ...getHeaders(ctx.headers),
168
- ...omitNullAndUndefined(getParsedValue(arrayToObject(headers)))
169
+ ...omitNullAndUndefined(getParsedValue(arrayToObject(headers), variables))
169
170
  },
170
- params: getParsedValue(arrayToObject(params)),
171
- data: getParsedValue(data)
171
+ params: getParsedValue(arrayToObject(params), variables),
172
+ data: getParsedValue(data, variables)
172
173
  };
173
174
  console.log(axiosRequestConfig);
174
175
  const requestUrl = import_axios.default.getUri(axiosRequestConfig);
@@ -205,5 +206,6 @@ async function send(ctx, next) {
205
206
  }
206
207
  // Annotate the CommonJS export names for ESM import in node:
207
208
  0 && (module.exports = {
209
+ getParsedValue,
208
210
  send
209
211
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-action-custom-request",
3
- "version": "1.3.38-beta",
3
+ "version": "1.4.0-alpha",
4
4
  "main": "dist/server/index.js",
5
5
  "homepage": "https://docs.nocobase.com/handbook/action-custom-request",
6
6
  "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/action-custom-request",
@@ -22,7 +22,7 @@
22
22
  "@nocobase/server": "1.x",
23
23
  "@nocobase/test": "1.x"
24
24
  },
25
- "gitHead": "1b9490667c9224cd0b179cbf75e10a581c49b230",
25
+ "gitHead": "f097a2bddec152522b5645bd5d451f4c866d2060",
26
26
  "keywords": [
27
27
  "Actions"
28
28
  ]
File without changes
File without changes