@nocobase/plugin-environment-variables 1.6.0-alpha.17 → 1.6.0-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +3 -3
- package/dist/locale/zh-CN.json +2 -2
- package/dist/server/plugin.d.ts +5 -3
- package/dist/server/plugin.js +40 -25
- package/package.json +6 -6
- package/dist/server/AesEncryptor.d.ts +0 -17
- package/dist/server/AesEncryptor.js +0 -97
package/dist/client/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("@formily/core"),require("@nocobase/client"),require("antd"),require("@ant-design/icons"),require("@formily/react"),require("@formily/antd-v5")):"function"==typeof define&&define.amd?define("@nocobase/plugin-environment-variables",["react","@formily/core","@nocobase/client","antd","@ant-design/icons","@formily/react","@formily/antd-v5"],t):"object"==typeof exports?exports["@nocobase/plugin-environment-variables"]=t(require("react"),require("@formily/core"),require("@nocobase/client"),require("antd"),require("@ant-design/icons"),require("@formily/react"),require("@formily/antd-v5")):e["@nocobase/plugin-environment-variables"]=t(e.react,e["@formily/core"],e["@nocobase/client"],e.antd,e["@ant-design/icons"],e["@formily/react"],e["@formily/antd-v5"])}(self,function(e,t,n,r,o,a,l){return function(){"use strict";var i={482:function(e){e.exports=o},632:function(e){e.exports=l},563:function(e){e.exports=t},505:function(e){e.exports=a},772:function(e){e.exports=n},721:function(e){e.exports=r},156:function(t){t.exports=e}},u={};function c(e){var t=u[e];if(void 0!==t)return t.exports;var n=u[e]={exports:{}};return i[e](n,n.exports,c),n.exports}c.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return c.d(t,{a:t}),t},c.d=function(e,t){for(var n in t)c.o(t,n)&&!c.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},c.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},c.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};c.r(s),c.d(s,{PluginEnvironmentVariablesClient:function(){return U},default:function(){return H}});var f=c("772"),p=c("505"),m=c("156"),d=c.n(m),b=(0,m.createContext)({}),y=function(e){var t=(0,f.useRequest)({url:"environmentVariables?paginate=false"});return d().createElement(b.Provider,{value:{variablesRequest:t}},e.children)},v=(0,p.observer)(function(e){return(0,f.useIsAdminPage)()?d().createElement(y,e):d().createElement(d().Fragment,null,e.children)},{displayName:"EnvironmentVariablesAndSecretsProvider"}),h=c("482"),g=c("632"),x=c("563"),E=c("721"),w=/^[A-Za-z][A-Za-z0-9_]*$/,S=JSON.parse('{"u2":"@nocobase/plugin-environment-variables"}');function O(){var e=(0,f.useApp)();return function(t){return e.i18n.t(t,{ns:[S.u2,"client"]})}}function k(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function A(e){if(Array.isArray(e))return e}function j(e,t,n,r,o,a,l){try{var i=e[a](l),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,o)}function q(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var a=e.apply(t,n);function l(e){j(a,r,o,l,i,"next",e)}function i(e){j(a,r,o,l,i,"throw",e)}l(void 0)})}}function P(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function F(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r,o,a;r=e,o=t,a=n[t],o in r?Object.defineProperty(r,o,{value:a,enumerable:!0,configurable:!0,writable:!0}):r[o]=a})}return e}function I(e,t){return A(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(n=o.next()).done)&&(a.push(n.value),!t||a.length!==t);l=!0);}catch(e){i=!0,r=e}finally{try{!l&&null!=o.return&&o.return()}finally{if(i)throw r}}return a}}(e,t)||R(e,t)||P()}function R(e,t){if(e){if("string"==typeof e)return k(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return k(e,t)}}function C(e,t){var n,r,o,a,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw TypeError("Generator is already executing.");for(;l;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return l.label++,{value:a[1],done:!1};case 5:l.label++,r=a[1],a=[0];continue;case 7:a=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){l=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){l.label=a[1];break}if(6===a[0]&&l.label<o[1]){l.label=o[1],o=a;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(a);break}o[2]&&l.ops.pop(),l.trys.pop();continue}a=t.call(e,l)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,i])}}}(0,x.registerValidateRules)({env_name_rule:function(e){return e?w.test(e)?"":"Only letters, numbers and underscores are allowed, and it must start with a letter.":""}});var T=(0,p.createSchemaField)({components:{FormItem:g.FormItem,Input:g.Input,Checkbox:g.Checkbox,Radio:g.Radio}}),B={type:"object",properties:{variables:{type:"string",title:'{{ t("Plain text") }}',"x-decorator":"FormItem","x-component":"Input.TextArea","x-component-props":{autoSize:{minRows:10,maxRows:20},placeholder:"FOO=aaa\nBAR=bbb\n "}},secret:{type:"string",title:'{{ t("Encrypted") }}',"x-decorator":"FormItem","x-component":"Input.TextArea","x-component-props":{autoSize:{minRows:10,maxRows:20},placeholder:"FOO=aaa\nBAR=bbb\n "}}}},V={type:"object",properties:{name:{type:"string",title:'{{ t("Name") }}',required:!0,"x-validator":{env_name_rule:!0},"x-decorator":"FormItem","x-component":"Input","x-disabled":"{{ !createOnly }}"},type:{type:"string",title:'{{ t("Type") }}',required:!0,"x-decorator":"FormItem","x-component":"Radio.Group",default:"default",enum:[{value:"default",label:'{{t("Plain text")}}'},{value:"secret",label:'{{t("Encrypted")}}'}]},value:{type:"string",title:'{{ t("Value") }}',required:!0,"x-decorator":"FormItem","x-component":"Input.TextArea"}}};function $(e){var t,n=e.request,r=e.setSelectRowKeys,o=E.App.useApp().modal,a=O(),l=(0,f.useAPIClient)(),i=n||{},u=i.data,c=i.loading,s=i.refresh,p={default:{label:a("Plain text"),color:"green"},secret:{label:a("Encrypted"),color:"red"}},m=l.resource("environmentVariables"),b=function(e){o.confirm({title:a("Delete variable"),content:a("Are you sure you want to delete it?"),onOk:function(){return q(function(){return C(this,function(t){switch(t.label){case 0:return[4,m.destroy({filterByTk:e.name})];case 1:return t.sent(),s(),[2]}})})()}})};var y=(t=q(function(e){var t;return C(this,function(r){return(t=(0,g.FormDrawer)({title:a("Edit")},function(){var r;return d().createElement(g.FormLayout,{layout:"vertical"},d().createElement(f.SchemaComponentOptions,{scope:{createOnly:!1,t:a}},d().createElement(T,{schema:V})),d().createElement(g.FormDrawer.Footer,null,d().createElement(g.FormButtonGroup,{align:"right"},d().createElement(g.Reset,{onClick:function(){t.close()}},a("Cancel")),d().createElement(g.Submit,{onSubmit:(r=q(function(t){return C(this,function(r){switch(r.label){case 0:return[4,l.request({url:"environmentVariables:update?filterByTk=".concat(e.name),method:"post",data:F({},t)})];case 1:return r.sent(),n.refresh(),[2]}})}),function(e){return r.apply(this,arguments)})},a("Submit")))))})).open({initialValues:F({},e)}),[2]})}),function(e){return t.apply(this,arguments)});return d().createElement("div",null,d().createElement(E.Table,{loading:c,size:"middle",rowKey:"name",dataSource:null==u?void 0:u.data,pagination:!1,columns:[{title:a("Name"),dataIndex:"name",ellipsis:!0},{title:a("Type"),dataIndex:"type",render:function(e){return d().createElement(E.Tag,{color:p[e].color},p[e].label)}},{title:a("Value"),ellipsis:!0,render:function(e){return d().createElement("div",null,"default"===e.type?e.value:"******")}},{title:a("Actions"),width:200,render:function(e){return d().createElement(E.Space,null,d().createElement("a",{onClick:function(){return y(e)}},a("Edit")),d().createElement("a",{onClick:function(){return b(e)}},a("Delete")))}}],rowSelection:{type:"checkbox",onChange:function(e,t){r(e)}}}))}function _(){var e,t,n,r=(0,f.useAPIClient)(),o=O(),a=E.App.useApp().modal,l=(0,m.useContext)(b).variablesRequest,i=I((0,m.useState)([]),2),u=i[0],c=i[1],s=r.resource("environmentVariables");var y=(e=q(function(e){var t;return C(this,function(n){switch(n.label){case 0:return t=Object.entries(e).map(function(e){var t,n,r=I(e,2),o=r[0];return(t=r[1],n=o,t.trim().split("\n").map(function(e){var t,r=A(t=e.split("="))||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||R(t)||P(),o=r[0],a=r.slice(1);return o&&{name:o.trim(),value:a.join("=").trim(),type:"secret"===n?"secret":"default"}})).filter(Boolean)}),[4,r.request({url:"environmentVariables:create",method:"post",data:t.flat()})];case 1:return n.sent(),[2]}})}),function(t){return e.apply(this,arguments)}),v=[{name:"name",title:o("Name"),operators:[{label:'{{t("contains")}}',value:"$includes",selected:!0},{label:'{{t("does not contain")}}',value:"$notIncludes"},{label:'{{t("is")}}',value:"$eq"},{label:'{{t("is not")}}',value:"$ne"}],schema:{type:"string",title:o("Name"),"x-component":"Input"}},{name:"type",title:o("Type"),operators:[{label:'{{t("is")}}',value:"$match",selected:!0,schema:{"x-component":"Select","x-component-props":{mode:"tags"}}},{label:'{{t("is not")}}',value:"$notMatch",schema:{"x-component":"Select","x-component-props":{mode:"tags"}}}],schema:{type:"string",title:o("Type"),"x-component":"Select",enum:[{value:"default",label:'{{t("Plain text")}}'},{value:"secret",label:'{{t("Encrypted")}}'}]}},{name:"value",title:o("Value"),operators:[{label:'{{t("contains")}}',value:"$includes",selected:!0},{label:'{{t("does not contain")}}',value:"$notIncludes"},{label:'{{t("is")}}',value:"$eq"},{label:'{{t("is not")}}',value:"$ne"}],schema:{type:"string",title:o("Value"),"x-component":"Input"}}];return d().createElement("div",null,(null==l?void 0:null===(n=l.data)||void 0===n?void 0:null===(t=n.meta)||void 0===t?void 0:t.updated)&&d().createElement(E.Alert,{type:"warning",style:{marginBottom:"1.2em",alignItems:"center"},description:d().createElement("div",null,o("Environment variables have been updated. A restart is required for the changes to take effect.")," "),action:d().createElement(E.Button,{size:"middle",type:"primary",onClick:q(function(){return C(this,function(e){switch(e.label){case 0:return[4,r.resource("app").refresh()];case 1:return e.sent(),[2]}})})},o("Restart now"))}),d().createElement(E.Card,null,d().createElement("div",{style:{float:"left"}},d().createElement(f.SchemaComponent,{schema:{name:"filter",type:"object",title:'{{ t("Filter") }}',default:{$and:[{name:{$includes:""}}]},"x-component":"Filter.Action",enum:v,"x-use-component-props":function(){var e,t=(0,p.useField)(),n=l.run;return{options:v,onSubmit:(e=q(function(e){return C(this,function(r){return n(e),t.setValue(e),[2]})}),function(t){return e.apply(this,arguments)}),onReset:function(e){t.setValue(e)}}}},scope:{t:o}})),d().createElement(E.Flex,{justify:"end",style:{marginBottom:16}},d().createElement(E.Space,null,d().createElement(E.Button,{icon:d().createElement(h.ReloadOutlined,null),onClick:function(){var e;null==l||null===(e=l.refresh)||void 0===e||e.call(l)}},o("Refresh")),d().createElement(E.Button,{icon:d().createElement(h.DeleteOutlined,null),onClick:function(){u.length>0&&a.confirm({title:o("Delete variable"),content:o("Are you sure you want to delete it?"),onOk:function(){return q(function(){var e;return C(this,function(t){switch(t.label){case 0:return[4,s.destroy({filterByTk:u})];case 1:return t.sent(),null==l||null===(e=l.refresh)||void 0===e||e.call(l),[2]}})})()}})}},o("Delete")),d().createElement(E.Dropdown,{menu:{onClick:function(e){(0,g.FormDrawer)({variable:o("Add variable"),bulk:o("Bulk import")}[e.key],function(){var t;return d().createElement(g.FormLayout,{layout:"vertical"},d().createElement(f.SchemaComponentOptions,{scope:{createOnly:!0,t:o}},d().createElement(T,{schema:"bulk"===e.key?B:V})),d().createElement(g.FormDrawer.Footer,null,d().createElement(g.FormButtonGroup,{align:"right"},d().createElement(g.Reset,null,o("Cancel")),d().createElement(g.Submit,{onSubmit:(t=q(function(t){return C(this,function(n){switch(n.label){case 0:if("bulk"!==e.key)return[3,2];return[4,y(t)];case 1:return n.sent(),l.refresh(),[3,4];case 2:return[4,r.request({url:"environmentVariables:create",method:"post",data:F({},t)})];case 3:n.sent(),l.refresh(),n.label=4;case 4:return[2]}})}),function(e){return t.apply(this,arguments)})},o("Submit")))))}).open({initialValues:{}}).then(console.log).catch(console.log)},items:[{key:"variable",label:o("Add variable")},{type:"divider"},{key:"bulk",label:o("Bulk import")}]}},d().createElement(E.Button,{type:"primary",icon:d().createElement(h.PlusOutlined,null)},o("Add new")," ",d().createElement(h.DownOutlined,null))))),d().createElement($,{request:l,setSelectRowKeys:c})))}function D(){return d().createElement(_,null)}var M=function(){var e,t=O(),n=(0,m.useContext)(b).variablesRequest||{},r=n.data;return!n.loading&&(null==r?void 0:null===(e=r.data)||void 0===e?void 0:e.length)?{name:"$env",title:t("Environment variables"),value:"$env",label:t("Environment variables"),children:null==r?void 0:r.data.map(function(e){return{title:e.name,name:e.name,value:e.name,label:e.name}}).filter(Boolean)}:null};function z(e,t,n,r,o,a,l){try{var i=e[a](l),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,o)}function G(e,t,n){return(G=J()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&L(o,n.prototype),o}).apply(null,arguments)}function N(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function K(e){return(K=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function L(e,t){return(L=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function Z(e){var t="function"==typeof Map?new Map:void 0;return(Z=function(e){var n;if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return G(e,arguments,K(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),L(r,e)})(e)}function J(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(J=function(){return!!e})()}var U=function(e){var t,n,r;function o(){var e,t,n;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,o),e=this,t=o,n=arguments,t=K(t),function(e,t){return t&&("object"===function(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}(t)||"function"==typeof t)?t:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,J()?Reflect.construct(t,n||[],K(e).constructor):t.apply(e,n))}return!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&L(e,t)}(o,e),t=o,n=[{key:"load",value:function(){var e,t=this;return(e=function(){return function(e,t){var n,r,o,a,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw TypeError("Generator is already executing.");for(;l;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return l.label++,{value:a[1],done:!1};case 5:l.label++,r=a[1],a=[0];continue;case 7:a=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){l=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){l.label=a[1];break}if(6===a[0]&&l.label<o[1]){l.label=o[1],o=a;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(a);break}o[2]&&l.ops.pop(),l.trys.pop();continue}a=t.call(e,l)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,i])}}}(this,function(e){return t.app.pluginSettingsManager.add("environment",{title:t.t("Environment variables"),icon:"TableOutlined",Component:D}),t.app.addGlobalVar("$env",M),t.app.use(v),[2]})},function(){var t=this,n=arguments;return new Promise(function(r,o){var a=e.apply(t,n);function l(e){z(a,r,o,l,i,"next",e)}function i(e){z(a,r,o,l,i,"throw",e)}l(void 0)})})()}}],N(t.prototype,n),o}(Z(f.Plugin)),H=U;return s}()});
|
|
10
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("@formily/core"),require("@nocobase/client"),require("antd"),require("@ant-design/icons"),require("@formily/react"),require("@formily/antd-v5")):"function"==typeof define&&define.amd?define("@nocobase/plugin-environment-variables",["react","@formily/core","@nocobase/client","antd","@ant-design/icons","@formily/react","@formily/antd-v5"],t):"object"==typeof exports?exports["@nocobase/plugin-environment-variables"]=t(require("react"),require("@formily/core"),require("@nocobase/client"),require("antd"),require("@ant-design/icons"),require("@formily/react"),require("@formily/antd-v5")):e["@nocobase/plugin-environment-variables"]=t(e.react,e["@formily/core"],e["@nocobase/client"],e.antd,e["@ant-design/icons"],e["@formily/react"],e["@formily/antd-v5"])}(self,function(e,t,n,r,o,a,l){return function(){"use strict";var i={482:function(e){e.exports=o},632:function(e){e.exports=l},563:function(e){e.exports=t},505:function(e){e.exports=a},772:function(e){e.exports=n},721:function(e){e.exports=r},156:function(t){t.exports=e}},u={};function c(e){var t=u[e];if(void 0!==t)return t.exports;var n=u[e]={exports:{}};return i[e](n,n.exports,c),n.exports}c.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return c.d(t,{a:t}),t},c.d=function(e,t){for(var n in t)c.o(t,n)&&!c.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},c.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},c.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};c.r(s),c.d(s,{PluginEnvironmentVariablesClient:function(){return U},default:function(){return H}});var f=c("772"),p=c("505"),m=c("156"),d=c.n(m),b=(0,m.createContext)({}),y=function(e){var t=(0,f.useRequest)({url:"environmentVariables?paginate=false"});return d().createElement(b.Provider,{value:{variablesRequest:t}},e.children)},v=(0,p.observer)(function(e){return(0,f.useIsAdminPage)()?d().createElement(y,e):d().createElement(d().Fragment,null,e.children)},{displayName:"EnvironmentVariablesAndSecretsProvider"}),h=c("482"),g=c("632"),x=c("563"),w=c("721"),E=/^[A-Za-z][A-Za-z0-9_]*$/,S=JSON.parse('{"u2":"@nocobase/plugin-environment-variables"}');function O(){var e=(0,f.useApp)();return function(t){return e.i18n.t(t,{ns:[S.u2,"client"]})}}function k(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function A(e){if(Array.isArray(e))return e}function j(e,t,n,r,o,a,l){try{var i=e[a](l),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,o)}function q(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var a=e.apply(t,n);function l(e){j(a,r,o,l,i,"next",e)}function i(e){j(a,r,o,l,i,"throw",e)}l(void 0)})}}function P(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function F(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r,o,a;r=e,o=t,a=n[t],o in r?Object.defineProperty(r,o,{value:a,enumerable:!0,configurable:!0,writable:!0}):r[o]=a})}return e}function I(e,t){return A(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(n=o.next()).done)&&(a.push(n.value),!t||a.length!==t);l=!0);}catch(e){i=!0,r=e}finally{try{!l&&null!=o.return&&o.return()}finally{if(i)throw r}}return a}}(e,t)||R(e,t)||P()}function R(e,t){if(e){if("string"==typeof e)return k(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return k(e,t)}}function C(e,t){var n,r,o,a,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw TypeError("Generator is already executing.");for(;l;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return l.label++,{value:a[1],done:!1};case 5:l.label++,r=a[1],a=[0];continue;case 7:a=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){l=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){l.label=a[1];break}if(6===a[0]&&l.label<o[1]){l.label=o[1],o=a;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(a);break}o[2]&&l.ops.pop(),l.trys.pop();continue}a=t.call(e,l)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,i])}}}(0,x.registerValidateRules)({env_name_rule:function(e){return e?E.test(e)?"":"Only letters, numbers and underscores are allowed, and it must start with a letter.":""}});var V=(0,p.createSchemaField)({components:{FormItem:g.FormItem,Input:g.Input,Checkbox:g.Checkbox,Radio:g.Radio}}),T={type:"object",properties:{variables:{type:"string",title:'{{ t("Plain text") }}',"x-decorator":"FormItem","x-component":"Input.TextArea","x-component-props":{autoSize:{minRows:10,maxRows:20},placeholder:"FOO=aaa\nBAR=bbb\n "}},secret:{type:"string",title:'{{ t("Encrypted") }}',"x-decorator":"FormItem","x-component":"Input.TextArea","x-component-props":{autoSize:{minRows:10,maxRows:20},placeholder:"FOO=aaa\nBAR=bbb\n "}}}},B={type:"object",properties:{name:{type:"string",title:'{{ t("Name") }}',required:!0,"x-validator":{env_name_rule:!0},"x-decorator":"FormItem","x-component":"Input","x-disabled":"{{ !createOnly }}"},type:{type:"string",title:'{{ t("Type") }}',required:!0,"x-decorator":"FormItem","x-component":"Radio.Group",default:"default",enum:[{value:"default",label:'{{t("Plain text")}}'},{value:"secret",label:'{{t("Encrypted")}}'}]},value:{type:"string",title:'{{ t("Value") }}',required:!0,"x-decorator":"FormItem","x-component":"Input.TextArea"}}};function $(e){var t,n=e.request,r=e.setSelectRowKeys,o=w.App.useApp().modal,a=O(),l=(0,f.useAPIClient)(),i=n||{},u=i.data,c=i.loading,s=i.refresh,p={default:{label:a("Plain text"),color:"green"},secret:{label:a("Encrypted"),color:"red"}},m=l.resource("environmentVariables"),b=function(e){o.confirm({title:a("Delete variable"),content:a("Are you sure you want to delete it?"),onOk:function(){return q(function(){return C(this,function(t){switch(t.label){case 0:return[4,m.destroy({filterByTk:e.name})];case 1:return t.sent(),s(),[2]}})})()}})};var y=(t=q(function(e){var t;return C(this,function(r){return(t=(0,g.FormDrawer)({title:a("Edit")},function(){var r;return d().createElement(g.FormLayout,{layout:"vertical"},d().createElement(f.SchemaComponentOptions,{scope:{createOnly:!1,t:a}},d().createElement(V,{schema:B})),d().createElement(g.FormDrawer.Footer,null,d().createElement(g.FormButtonGroup,{align:"right"},d().createElement(g.Reset,{onClick:function(){t.close()}},a("Cancel")),d().createElement(g.Submit,{onSubmit:(r=q(function(t){return C(this,function(r){switch(r.label){case 0:return[4,l.request({url:"environmentVariables:update?filterByTk=".concat(e.name),method:"post",data:F({},t)})];case 1:return r.sent(),n.refresh(),[2]}})}),function(e){return r.apply(this,arguments)})},a("Submit")))))})).open({initialValues:F({},e)}),[2]})}),function(e){return t.apply(this,arguments)});return d().createElement("div",null,d().createElement(w.Table,{loading:c,size:"middle",rowKey:"name",dataSource:null==u?void 0:u.data,pagination:!1,columns:[{title:a("Name"),dataIndex:"name",ellipsis:!0},{title:a("Type"),dataIndex:"type",render:function(e){return d().createElement(w.Tag,{color:p[e].color},p[e].label)}},{title:a("Value"),ellipsis:!0,render:function(e){return d().createElement("div",null,"default"===e.type?e.value:"******")}},{title:a("Actions"),width:200,render:function(e){return d().createElement(w.Space,null,d().createElement("a",{onClick:function(){return y(e)}},a("Edit")),d().createElement("a",{onClick:function(){return b(e)}},a("Delete")))}}],rowSelection:{type:"checkbox",onChange:function(e,t){r(e)}}}))}function _(){var e,t,n,r=(0,f.useAPIClient)(),o=O(),a=w.App.useApp().modal,l=(0,m.useContext)(b).variablesRequest,i=I((0,m.useState)([]),2),u=i[0],c=i[1],s=r.resource("environmentVariables");var y=(e=q(function(e){var t;return C(this,function(n){switch(n.label){case 0:return t=Object.entries(e).map(function(e){var t,n,r=I(e,2),o=r[0];return(t=r[1],n=o,t.trim().split("\n").map(function(e){var t,r=A(t=e.split("="))||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||R(t)||P(),o=r[0],a=r.slice(1);return o&&{name:o.trim(),value:a.join("=").trim(),type:"secret"===n?"secret":"default"}})).filter(Boolean)}),[4,r.request({url:"environmentVariables:create",method:"post",data:t.flat()})];case 1:return n.sent(),[2]}})}),function(t){return e.apply(this,arguments)}),v=[{name:"name",title:o("Name"),operators:[{label:'{{t("contains")}}',value:"$includes",selected:!0},{label:'{{t("does not contain")}}',value:"$notIncludes"},{label:'{{t("is")}}',value:"$eq"},{label:'{{t("is not")}}',value:"$ne"}],schema:{type:"string",title:o("Name"),"x-component":"Input"}},{name:"type",title:o("Type"),operators:[{label:'{{t("is")}}',value:"$match",selected:!0,schema:{"x-component":"Select","x-component-props":{mode:"tags"}}},{label:'{{t("is not")}}',value:"$notMatch",schema:{"x-component":"Select","x-component-props":{mode:"tags"}}}],schema:{type:"string",title:o("Type"),"x-component":"Select",enum:[{value:"default",label:'{{t("Plain text")}}'},{value:"secret",label:'{{t("Encrypted")}}'}]}},{name:"value",title:o("Value"),operators:[{label:'{{t("contains")}}',value:"$includes",selected:!0},{label:'{{t("does not contain")}}',value:"$notIncludes"},{label:'{{t("is")}}',value:"$eq"},{label:'{{t("is not")}}',value:"$ne"}],schema:{type:"string",title:o("Value"),"x-component":"Input"}}];return d().createElement("div",null,(null==l?void 0:null===(n=l.data)||void 0===n?void 0:null===(t=n.meta)||void 0===t?void 0:t.updated)&&d().createElement(w.Alert,{type:"warning",style:{marginBottom:"1.2em",alignItems:"center"},description:d().createElement("div",null,o("Variables and secrets have been updated. A restart is required for the changes to take effect.")," "),action:d().createElement(w.Button,{size:"middle",type:"primary",onClick:q(function(){return C(this,function(e){switch(e.label){case 0:return[4,r.resource("app").refresh()];case 1:return e.sent(),[2]}})})},o("Restart now"))}),d().createElement(w.Card,null,d().createElement("div",{style:{float:"left"}},d().createElement(f.SchemaComponent,{schema:{name:"filter",type:"object",title:'{{ t("Filter") }}',default:{$and:[{name:{$includes:""}}]},"x-component":"Filter.Action",enum:v,"x-use-component-props":function(){var e,t=(0,p.useField)(),n=l.run;return{options:v,onSubmit:(e=q(function(e){return C(this,function(r){return n(e),t.setValue(e),[2]})}),function(t){return e.apply(this,arguments)}),onReset:function(e){t.setValue(e)}}}},scope:{t:o}})),d().createElement(w.Flex,{justify:"end",style:{marginBottom:16}},d().createElement(w.Space,null,d().createElement(w.Button,{icon:d().createElement(h.ReloadOutlined,null),onClick:function(){var e;null==l||null===(e=l.refresh)||void 0===e||e.call(l)}},o("Refresh")),d().createElement(w.Button,{icon:d().createElement(h.DeleteOutlined,null),onClick:function(){u.length>0&&a.confirm({title:o("Delete variable"),content:o("Are you sure you want to delete it?"),onOk:function(){return q(function(){var e;return C(this,function(t){switch(t.label){case 0:return[4,s.destroy({filterByTk:u})];case 1:return t.sent(),null==l||null===(e=l.refresh)||void 0===e||e.call(l),[2]}})})()}})}},o("Delete")),d().createElement(w.Dropdown,{menu:{onClick:function(e){(0,g.FormDrawer)({variable:o("Add variable"),bulk:o("Bulk import")}[e.key],function(){var t;return d().createElement(g.FormLayout,{layout:"vertical"},d().createElement(f.SchemaComponentOptions,{scope:{createOnly:!0,t:o}},d().createElement(V,{schema:"bulk"===e.key?T:B})),d().createElement(g.FormDrawer.Footer,null,d().createElement(g.FormButtonGroup,{align:"right"},d().createElement(g.Reset,null,o("Cancel")),d().createElement(g.Submit,{onSubmit:(t=q(function(t){return C(this,function(n){switch(n.label){case 0:if("bulk"!==e.key)return[3,2];return[4,y(t)];case 1:return n.sent(),l.refresh(),[3,4];case 2:return[4,r.request({url:"environmentVariables:create",method:"post",data:F({},t)})];case 3:n.sent(),l.refresh(),n.label=4;case 4:return[2]}})}),function(e){return t.apply(this,arguments)})},o("Submit")))))}).open({initialValues:{}}).then(console.log).catch(console.log)},items:[{key:"variable",label:o("Add variable")},{type:"divider"},{key:"bulk",label:o("Bulk import")}]}},d().createElement(w.Button,{type:"primary",icon:d().createElement(h.PlusOutlined,null)},o("Add new")," ",d().createElement(h.DownOutlined,null))))),d().createElement($,{request:l,setSelectRowKeys:c})))}function D(){return d().createElement(_,null)}var M=function(){var e,t=O(),n=(0,m.useContext)(b).variablesRequest||{},r=n.data;return!n.loading&&(null==r?void 0:null===(e=r.data)||void 0===e?void 0:e.length)?{name:"$env",title:t("Variables and secrets"),value:"$env",label:t("Variables and secrets"),children:null==r?void 0:r.data.map(function(e){return{title:e.name,name:e.name,value:e.name,label:e.name}}).filter(Boolean)}:null};function z(e,t,n,r,o,a,l){try{var i=e[a](l),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,o)}function G(e,t,n){return(G=J()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&L(o,n.prototype),o}).apply(null,arguments)}function N(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function K(e){return(K=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function L(e,t){return(L=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function Z(e){var t="function"==typeof Map?new Map:void 0;return(Z=function(e){var n;if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return G(e,arguments,K(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),L(r,e)})(e)}function J(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(J=function(){return!!e})()}var U=function(e){var t,n,r;function o(){var e,t,n;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,o),e=this,t=o,n=arguments,t=K(t),function(e,t){return t&&("object"===function(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}(t)||"function"==typeof t)?t:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,J()?Reflect.construct(t,n||[],K(e).constructor):t.apply(e,n))}return!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&L(e,t)}(o,e),t=o,n=[{key:"load",value:function(){var e,t=this;return(e=function(){return function(e,t){var n,r,o,a,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw TypeError("Generator is already executing.");for(;l;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return l.label++,{value:a[1],done:!1};case 5:l.label++,r=a[1],a=[0];continue;case 7:a=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){l=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){l.label=a[1];break}if(6===a[0]&&l.label<o[1]){l.label=o[1],o=a;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(a);break}o[2]&&l.ops.pop(),l.trys.pop();continue}a=t.call(e,l)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,i])}}}(this,function(e){return t.app.pluginSettingsManager.add("environment",{title:t.t("Variables and secrets"),icon:"TableOutlined",Component:D}),t.app.addGlobalVar("$env",M),t.app.use(v),[2]})},function(){var t=this,n=arguments;return new Promise(function(r,o){var a=e.apply(t,n);function l(e){z(a,r,o,l,i,"next",e)}function i(e){z(a,r,o,l,i,"throw",e)}l(void 0)})})()}}],N(t.prototype,n),o}(Z(f.Plugin)),H=U;return s}()});
|
package/dist/externalVersion.js
CHANGED
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
11
|
"@formily/react": "2.3.0",
|
|
12
|
-
"@nocobase/client": "1.6.0-alpha.
|
|
12
|
+
"@nocobase/client": "1.6.0-alpha.19",
|
|
13
13
|
"react": "18.2.0",
|
|
14
|
-
"@nocobase/server": "1.6.0-alpha.
|
|
14
|
+
"@nocobase/server": "1.6.0-alpha.19",
|
|
15
15
|
"@ant-design/icons": "5.2.6",
|
|
16
16
|
"@formily/antd-v5": "1.1.9",
|
|
17
17
|
"@formily/core": "2.3.0",
|
|
18
18
|
"antd": "5.12.8",
|
|
19
|
-
"@nocobase/database": "1.6.0-alpha.
|
|
19
|
+
"@nocobase/database": "1.6.0-alpha.19"
|
|
20
20
|
};
|
package/dist/locale/zh-CN.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"Environment": "环境",
|
|
3
|
-
"
|
|
3
|
+
"Variables and secrets": "变量和密钥",
|
|
4
4
|
"Variables": "变量",
|
|
5
5
|
"Secrets": "密钥",
|
|
6
6
|
"Add variable": "添加变量",
|
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
"Encrypted": "加密",
|
|
13
13
|
"Delete variable": "删除变量",
|
|
14
14
|
"Restart now": "立即重启",
|
|
15
|
-
"
|
|
15
|
+
"Variables and secrets have been updated. A restart is required for the changes to take effect.": "检测到变量和密钥有更新,需重启应用才能生效。"
|
|
16
16
|
}
|
package/dist/server/plugin.d.ts
CHANGED
|
@@ -7,15 +7,17 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { Plugin } from '@nocobase/server';
|
|
10
|
-
import AesEncryptor from './AesEncryptor';
|
|
11
10
|
export declare class PluginEnvironmentVariablesServer extends Plugin {
|
|
12
|
-
aesEncryptor: AesEncryptor;
|
|
13
11
|
updated: boolean;
|
|
12
|
+
get aesEncryptor(): import("@nocobase/server").AesEncryptor;
|
|
14
13
|
handleSyncMessage(message: any): Promise<void>;
|
|
15
14
|
load(): Promise<void>;
|
|
16
|
-
createAesEncryptor(): Promise<void>;
|
|
17
15
|
registerACL(): void;
|
|
18
16
|
listEnvironmentVariables(): Promise<any>;
|
|
17
|
+
validateTexts(texts: Array<{
|
|
18
|
+
text: string;
|
|
19
|
+
secret: boolean;
|
|
20
|
+
}>): void;
|
|
19
21
|
setEnvironmentVariablesByText(texts: Array<{
|
|
20
22
|
text: string;
|
|
21
23
|
secret: boolean;
|
package/dist/server/plugin.js
CHANGED
|
@@ -7,11 +7,9 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
var __create = Object.create;
|
|
11
10
|
var __defProp = Object.defineProperty;
|
|
12
11
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
12
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
13
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
14
|
var __export = (target, all) => {
|
|
17
15
|
for (var name in all)
|
|
@@ -25,14 +23,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
25
23
|
}
|
|
26
24
|
return to;
|
|
27
25
|
};
|
|
28
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
-
mod
|
|
35
|
-
));
|
|
36
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
27
|
var plugin_exports = {};
|
|
38
28
|
__export(plugin_exports, {
|
|
@@ -41,11 +31,11 @@ __export(plugin_exports, {
|
|
|
41
31
|
});
|
|
42
32
|
module.exports = __toCommonJS(plugin_exports);
|
|
43
33
|
var import_server = require("@nocobase/server");
|
|
44
|
-
var import_path = __toESM(require("path"));
|
|
45
|
-
var import_AesEncryptor = __toESM(require("./AesEncryptor"));
|
|
46
34
|
class PluginEnvironmentVariablesServer extends import_server.Plugin {
|
|
47
|
-
aesEncryptor;
|
|
48
35
|
updated = false;
|
|
36
|
+
get aesEncryptor() {
|
|
37
|
+
return this.app.aesEncryptor;
|
|
38
|
+
}
|
|
49
39
|
async handleSyncMessage(message) {
|
|
50
40
|
const { type, name, value } = message;
|
|
51
41
|
if (type === "updated") {
|
|
@@ -58,20 +48,10 @@ class PluginEnvironmentVariablesServer extends import_server.Plugin {
|
|
|
58
48
|
}
|
|
59
49
|
}
|
|
60
50
|
async load() {
|
|
61
|
-
this.createAesEncryptor();
|
|
62
51
|
this.registerACL();
|
|
63
52
|
this.onEnvironmentSaved();
|
|
64
53
|
await this.loadVariables();
|
|
65
54
|
}
|
|
66
|
-
async createAesEncryptor() {
|
|
67
|
-
let key = process.env.ENV_VARS_AES_SECRET_KEY;
|
|
68
|
-
if (!key) {
|
|
69
|
-
key = await import_AesEncryptor.default.getOrGenerateKey(
|
|
70
|
-
import_path.default.resolve(process.cwd(), "storage", this.name, this.app.name, "aes_key.dat")
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
this.aesEncryptor = new import_AesEncryptor.default(key);
|
|
74
|
-
}
|
|
75
55
|
registerACL() {
|
|
76
56
|
this.app.acl.allow("environmentVariables", "list", "loggedIn");
|
|
77
57
|
this.app.acl.registerSnippet({
|
|
@@ -86,7 +66,39 @@ class PluginEnvironmentVariablesServer extends import_server.Plugin {
|
|
|
86
66
|
});
|
|
87
67
|
return items.map(({ name, type }) => ({ name, type }));
|
|
88
68
|
}
|
|
69
|
+
validateTexts(texts) {
|
|
70
|
+
if (!Array.isArray(texts)) {
|
|
71
|
+
throw new Error("texts parameter must be an array");
|
|
72
|
+
}
|
|
73
|
+
for (const item of texts) {
|
|
74
|
+
if (!item || typeof item !== "object") {
|
|
75
|
+
throw new Error("Each item in texts must be an object");
|
|
76
|
+
}
|
|
77
|
+
if (typeof item.text !== "string" || !item.text.trim()) {
|
|
78
|
+
throw new Error("text property must be a non-empty string");
|
|
79
|
+
}
|
|
80
|
+
if (typeof item.secret !== "boolean") {
|
|
81
|
+
throw new Error("secret property must be a boolean");
|
|
82
|
+
}
|
|
83
|
+
const lines = item.text.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
84
|
+
for (const line of lines) {
|
|
85
|
+
const equalIndex = line.indexOf("=");
|
|
86
|
+
if (equalIndex === -1) {
|
|
87
|
+
throw new Error(`Invalid environment variable format: ${line}`);
|
|
88
|
+
}
|
|
89
|
+
const key = line.slice(0, equalIndex).trim();
|
|
90
|
+
const value = line.slice(equalIndex + 1).trim();
|
|
91
|
+
if (!key) {
|
|
92
|
+
throw new Error(`Environment variable name cannot be empty`);
|
|
93
|
+
}
|
|
94
|
+
if (!value) {
|
|
95
|
+
throw new Error(`Environment variable "${key}" must have a value`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
89
100
|
async setEnvironmentVariablesByText(texts) {
|
|
101
|
+
this.validateTexts(texts);
|
|
90
102
|
const repository = this.db.getRepository("environmentVariables");
|
|
91
103
|
for (const { text, secret } of texts) {
|
|
92
104
|
const lines = text.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
@@ -98,10 +110,13 @@ class PluginEnvironmentVariablesServer extends import_server.Plugin {
|
|
|
98
110
|
}
|
|
99
111
|
const key = line.slice(0, equalIndex).trim();
|
|
100
112
|
const value = line.slice(equalIndex + 1).trim();
|
|
101
|
-
if (!key
|
|
102
|
-
this.app.log.warn(`Empty key
|
|
113
|
+
if (!key) {
|
|
114
|
+
this.app.log.warn(`Empty key found: ${line}`);
|
|
103
115
|
continue;
|
|
104
116
|
}
|
|
117
|
+
if (!value) {
|
|
118
|
+
throw new Error(`Empty value is not allowed for key: ${key}`);
|
|
119
|
+
}
|
|
105
120
|
await repository.create({
|
|
106
121
|
values: {
|
|
107
122
|
name: key,
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-environment-variables",
|
|
3
|
-
"version": "1.6.0-alpha.
|
|
3
|
+
"version": "1.6.0-alpha.19",
|
|
4
4
|
"main": "dist/server/index.js",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"@nocobase/client": "1.x",
|
|
7
7
|
"@nocobase/server": "1.x",
|
|
8
8
|
"@nocobase/test": "1.x"
|
|
9
9
|
},
|
|
10
|
-
"displayName": "
|
|
11
|
-
"displayName.zh-CN": "
|
|
12
|
-
"description": "Centralized
|
|
13
|
-
"description.zh-CN": "
|
|
10
|
+
"displayName": "Variables and secrets",
|
|
11
|
+
"displayName.zh-CN": "变量和密钥",
|
|
12
|
+
"description": "Centralized management of environment variables and secrets, used for sensitive data storage, configuration data reuse, multi-environment isolation, and more.",
|
|
13
|
+
"description.zh-CN": "集中管理环境变量和密钥,用于敏感数据存储、配置数据重用、多环境隔离等。",
|
|
14
14
|
"keywords": [
|
|
15
15
|
"System management"
|
|
16
16
|
],
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "667b67a161c841c01d4ab337afa42cd29d6cf540"
|
|
18
18
|
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
/// <reference types="node" />
|
|
10
|
-
declare class AesEncryptor {
|
|
11
|
-
private key;
|
|
12
|
-
constructor(key: Buffer);
|
|
13
|
-
encrypt(text: string): Promise<string>;
|
|
14
|
-
decrypt(encryptedText: string): Promise<string>;
|
|
15
|
-
static getOrGenerateKey(keyFilePath: string): Promise<Buffer>;
|
|
16
|
-
}
|
|
17
|
-
export default AesEncryptor;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __export = (target, all) => {
|
|
17
|
-
for (var name in all)
|
|
18
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
-
};
|
|
20
|
-
var __copyProps = (to, from, except, desc) => {
|
|
21
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
-
for (let key of __getOwnPropNames(from))
|
|
23
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
-
}
|
|
26
|
-
return to;
|
|
27
|
-
};
|
|
28
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
-
mod
|
|
35
|
-
));
|
|
36
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
-
var AesEncryptor_exports = {};
|
|
38
|
-
__export(AesEncryptor_exports, {
|
|
39
|
-
default: () => AesEncryptor_default
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(AesEncryptor_exports);
|
|
42
|
-
var import_crypto = __toESM(require("crypto"));
|
|
43
|
-
var import_promises = __toESM(require("fs/promises"));
|
|
44
|
-
var import_path = __toESM(require("path"));
|
|
45
|
-
class AesEncryptor {
|
|
46
|
-
key;
|
|
47
|
-
constructor(key) {
|
|
48
|
-
if (key.length !== 32) {
|
|
49
|
-
throw new Error("Key must be 32 bytes for AES-256 encryption.");
|
|
50
|
-
}
|
|
51
|
-
this.key = key;
|
|
52
|
-
}
|
|
53
|
-
async encrypt(text) {
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
try {
|
|
56
|
-
const iv = import_crypto.default.randomBytes(16);
|
|
57
|
-
const cipher = import_crypto.default.createCipheriv("aes-256-cbc", this.key, iv);
|
|
58
|
-
const encrypted = Buffer.concat([cipher.update(Buffer.from(text, "utf8")), cipher.final()]);
|
|
59
|
-
resolve(iv.toString("hex") + encrypted.toString("hex"));
|
|
60
|
-
} catch (error) {
|
|
61
|
-
reject(error);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
async decrypt(encryptedText) {
|
|
66
|
-
return new Promise((resolve, reject) => {
|
|
67
|
-
try {
|
|
68
|
-
const iv = Buffer.from(encryptedText.slice(0, 32), "hex");
|
|
69
|
-
const encrypted = Buffer.from(encryptedText.slice(32), "hex");
|
|
70
|
-
const decipher = import_crypto.default.createDecipheriv("aes-256-cbc", this.key, iv);
|
|
71
|
-
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
72
|
-
resolve(decrypted.toString("utf8"));
|
|
73
|
-
} catch (error) {
|
|
74
|
-
reject(error);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
static async getOrGenerateKey(keyFilePath) {
|
|
79
|
-
try {
|
|
80
|
-
const key = await import_promises.default.readFile(keyFilePath);
|
|
81
|
-
if (key.length !== 32) {
|
|
82
|
-
throw new Error("Invalid key length in file.");
|
|
83
|
-
}
|
|
84
|
-
return key;
|
|
85
|
-
} catch (error) {
|
|
86
|
-
if (error.code === "ENOENT") {
|
|
87
|
-
const key = import_crypto.default.randomBytes(32);
|
|
88
|
-
await import_promises.default.mkdir(import_path.default.dirname(keyFilePath), { recursive: true });
|
|
89
|
-
await import_promises.default.writeFile(keyFilePath, key);
|
|
90
|
-
return key;
|
|
91
|
-
} else {
|
|
92
|
-
throw new Error(`Failed to load key: ${error.message}`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
var AesEncryptor_default = AesEncryptor;
|