@nocobase/plugin-api-keys 2.1.0-alpha.13 → 2.1.0-alpha.15

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.
@@ -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-i18next"),require("ahooks"),require("dayjs"),require("@formily/shared"),require("react"),require("antd"),require("@nocobase/client"),require("@formily/react")):"function"==typeof define&&define.amd?define("@nocobase/plugin-api-keys",["react-i18next","ahooks","dayjs","@formily/shared","react","antd","@nocobase/client","@formily/react"],t):"object"==typeof exports?exports["@nocobase/plugin-api-keys"]=t(require("react-i18next"),require("ahooks"),require("dayjs"),require("@formily/shared"),require("react"),require("antd"),require("@nocobase/client"),require("@formily/react")):e["@nocobase/plugin-api-keys"]=t(e["react-i18next"],e.ahooks,e.dayjs,e["@formily/shared"],e.react,e.antd,e["@nocobase/client"],e["@formily/react"])}(self,function(e,t,r,n,o,i,u,a){return function(){"use strict";var c,l,f,s={230:function(e){e.exports=a},166:function(e){e.exports=n},342:function(e){e.exports=u},625:function(e){e.exports=t},59:function(e){e.exports=i},185:function(e){e.exports=r},155:function(e){e.exports=o},953:function(t){t.exports=e}},p={};function y(e){var t=p[e];if(void 0!==t)return t.exports;var r=p[e]={exports:{}};return s[e](r,r.exports,y),r.exports}y.m=s,y.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return y.d(t,{a:t}),t},y.d=function(e,t){for(var r in t)y.o(t,r)&&!y.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},y.f={},y.e=function(e){return Promise.all(Object.keys(y.f).reduce(function(t,r){return y.f[r](e,t),t},[]))},y.u=function(e){return"afb492ad2c67c11c.js"},y.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),y.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},d={},y.l=function(e,t,r,n){if(d[e])return void d[e].push(t);if(void 0!==r)for(var o,i,u=document.getElementsByTagName("script"),a=0;a<u.length;a++){var c=u[a];if(c.getAttribute("src")==e||c.getAttribute("data-rspack")=="@nocobase/plugin-api-keys:"+r){o=c;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,y.nc&&o.setAttribute("nonce",y.nc),o.setAttribute("data-rspack","@nocobase/plugin-api-keys:"+r),o.src=e),d[e]=[t];var l=function(t,r){o.onerror=o.onload=null,clearTimeout(f);var n=d[e];if(delete d[e],o.parentNode&&o.parentNode.removeChild(o),n&&n.forEach(function(e){return e(r)}),t)return t(r)},f=setTimeout(l.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=l.bind(null,o.onerror),o.onload=l.bind(null,o.onload),i&&document.head.appendChild(o)},y.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},y.g.importScripts&&(b=y.g.location+"");var d,b,h=y.g.document;if(!b&&h&&(h.currentScript&&"SCRIPT"===h.currentScript.tagName.toUpperCase()&&(b=h.currentScript.src),!b)){var v=h.getElementsByTagName("script");if(v.length)for(var g=v.length-1;g>-1&&(!b||!/^http(s?):/.test(b));)b=v[g--].src}if(!b)throw Error("Automatic publicPath is not supported in this browser");y.p=b.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),c={889:0},y.f.j=function(e,t){var r=y.o(c,e)?c[e]:void 0;if(0!==r)if(r)t.push(r[2]);else{var n=new Promise(function(t,n){r=c[e]=[t,n]});t.push(r[2]=n);var o=y.p+y.u(e),i=Error();y.l(o,function(t){if(y.o(c,e)&&(0!==(r=c[e])&&(c[e]=void 0),r)){var n=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;i.message="Loading chunk "+e+" failed.\n("+n+": "+o+")",i.name="ChunkLoadError",i.type=n,i.request=o,r[1](i)}},"chunk-"+e,e)}},l=function(e,t){var r,n,o=t[0],i=t[1],u=t[2],a=0;if(o.some(function(e){return 0!==c[e]})){for(r in i)y.o(i,r)&&(y.m[r]=i[r]);u&&u(y)}for(e&&e(t);a<o.length;a++)n=o[a],y.o(c,n)&&c[n]&&c[n][0](),c[n]=0},(f=self.webpackChunk_nocobase_plugin_api_keys=self.webpackChunk_nocobase_plugin_api_keys||[]).forEach(l.bind(null,0)),f.push=l.bind(null,f.push.bind(f));var m={},w=window.__nocobase_public_path__||"";if(!w&&window.location&&window.location.pathname){var k=window.location.pathname||"/",x=k.indexOf("/v2/");w=x>=0?k.slice(0,x+1):"/"}return w&&(w=w.replace(/\/v2\/?$/,"/")),w||(w="/"),"/"!==w.charAt(w.length-1)&&(w+="/"),y.p=w+"static/plugins/@nocobase/plugin-api-keys/dist/client/",!function(){y.r(m),y.d(m,{PluginAPIKeysClient:function(){return c}});var e=y(342);function t(e,t,r,n,o,i,u){try{var a=e[i](u),c=a.value}catch(e){r(e);return}a.done?t(c):Promise.resolve(c).then(n,o)}function r(e,t,n){return(r=u()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&o(i,r.prototype),i}).apply(null,arguments)}function n(e){return(n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(e){var t="function"==typeof Map?new Map:void 0;return(i=function(e){if(null===e||-1===Function.toString.call(e).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,i)}function i(){return r(e,arguments,n(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),o(i,e)})(e)}function u(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(u=function(){return!!e})()}var a=(0,e.lazy)(function(){return y.e("252").then(y.bind(y,847))},"Configuration").Configuration,c=function(e){var r;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function i(){var e,t;if(!(this instanceof i))throw TypeError("Cannot call a class as a function");return e=i,t=arguments,e=n(e),function(e,t){var r;if(t&&("object"==((r=t)&&"u">typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,u()?Reflect.construct(e,t||[],n(this).constructor):e.apply(this,t))}return i.prototype=Object.create(e&&e.prototype,{constructor:{value:i,writable:!0,configurable:!0}}),e&&o(i,e),r=[{key:"load",value:function(){var e;return(e=function(){return function(e,t){var r,n,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},u=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),a=Object.defineProperty;return a(u,"next",{value:c(0)}),a(u,"throw",{value:c(1)}),a(u,"return",{value:c(2)}),"function"==typeof Symbol&&a(u,Symbol.iterator,{value:function(){return this}}),u;function c(a){return function(c){var l=[a,c];if(r)throw TypeError("Generator is already executing.");for(;u&&(u=0,l[0]&&(i=0)),i;)try{if(r=1,n&&(o=2&l[0]?n.return:l[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,l[1])).done)return o;switch(n=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,n=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],n=0}finally{r=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}(this,function(e){return this.pluginSettingsManager.add("api-keys",{icon:"KeyOutlined",title:this.t("API keys"),Component:a,aclSnippet:"pm.api-keys.configuration"}),[2]})},function(){var r=this,n=arguments;return new Promise(function(o,i){var u=e.apply(r,n);function a(e){t(u,o,i,a,c,"next",e)}function c(e){t(u,o,i,a,c,"throw",e)}a(void 0)})}).call(this)}}],function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(i.prototype,r),i}(i(e.Plugin));m.default=c}(),m}()});
10
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("ahooks"),require("react-i18next"),require("dayjs"),require("@formily/shared"),require("react"),require("antd"),require("@nocobase/client"),require("@formily/react")):"function"==typeof define&&define.amd?define("@nocobase/plugin-api-keys",["ahooks","react-i18next","dayjs","@formily/shared","react","antd","@nocobase/client","@formily/react"],t):"object"==typeof exports?exports["@nocobase/plugin-api-keys"]=t(require("ahooks"),require("react-i18next"),require("dayjs"),require("@formily/shared"),require("react"),require("antd"),require("@nocobase/client"),require("@formily/react")):e["@nocobase/plugin-api-keys"]=t(e.ahooks,e["react-i18next"],e.dayjs,e["@formily/shared"],e.react,e.antd,e["@nocobase/client"],e["@formily/react"])}(self,function(e,t,r,n,o,i,u,a){return function(){"use strict";var c,l,f,s={230:function(e){e.exports=a},166:function(e){e.exports=n},342:function(e){e.exports=u},625:function(t){t.exports=e},59:function(e){e.exports=i},185:function(e){e.exports=r},155:function(e){e.exports=o},953:function(e){e.exports=t}},p={};function d(e){var t=p[e];if(void 0!==t)return t.exports;var r=p[e]={exports:{}};return s[e](r,r.exports,d),r.exports}d.m=s,d.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return d.d(t,{a:t}),t},d.d=function(e,t){for(var r in t)d.o(t,r)&&!d.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},d.f={},d.e=function(e){return Promise.all(Object.keys(d.f).reduce(function(t,r){return d.f[r](e,t),t},[]))},d.u=function(e){return"afb492ad2c67c11c.js"},d.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),d.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},y={},d.l=function(e,t,r,n){if(y[e])return void y[e].push(t);if(void 0!==r)for(var o,i,u=document.getElementsByTagName("script"),a=0;a<u.length;a++){var c=u[a];if(c.getAttribute("src")==e||c.getAttribute("data-rspack")=="@nocobase/plugin-api-keys:"+r){o=c;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,d.nc&&o.setAttribute("nonce",d.nc),o.setAttribute("data-rspack","@nocobase/plugin-api-keys:"+r),o.src=e),y[e]=[t];var l=function(t,r){o.onerror=o.onload=null,clearTimeout(f);var n=y[e];if(delete y[e],o.parentNode&&o.parentNode.removeChild(o),n&&n.forEach(function(e){return e(r)}),t)return t(r)},f=setTimeout(l.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=l.bind(null,o.onerror),o.onload=l.bind(null,o.onload),i&&document.head.appendChild(o)},d.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},d.g.importScripts&&(b=d.g.location+"");var y,b,h=d.g.document;if(!b&&h&&(h.currentScript&&"SCRIPT"===h.currentScript.tagName.toUpperCase()&&(b=h.currentScript.src),!b)){var v=h.getElementsByTagName("script");if(v.length)for(var g=v.length-1;g>-1&&(!b||!/^http(s?):/.test(b));)b=v[g--].src}if(!b)throw Error("Automatic publicPath is not supported in this browser");d.p=b.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),c={889:0},d.f.j=function(e,t){var r=d.o(c,e)?c[e]:void 0;if(0!==r)if(r)t.push(r[2]);else{var n=new Promise(function(t,n){r=c[e]=[t,n]});t.push(r[2]=n);var o=d.p+d.u(e),i=Error();d.l(o,function(t){if(d.o(c,e)&&(0!==(r=c[e])&&(c[e]=void 0),r)){var n=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;i.message="Loading chunk "+e+" failed.\n("+n+": "+o+")",i.name="ChunkLoadError",i.type=n,i.request=o,r[1](i)}},"chunk-"+e,e)}},l=function(e,t){var r,n,o=t[0],i=t[1],u=t[2],a=0;if(o.some(function(e){return 0!==c[e]})){for(r in i)d.o(i,r)&&(d.m[r]=i[r]);u&&u(d)}for(e&&e(t);a<o.length;a++)n=o[a],d.o(c,n)&&c[n]&&c[n][0](),c[n]=0},(f=self.webpackChunk_nocobase_plugin_api_keys=self.webpackChunk_nocobase_plugin_api_keys||[]).forEach(l.bind(null,0)),f.push=l.bind(null,f.push.bind(f));var m={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src&&(e=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/")),!e){var r=window.__webpack_public_path__||"";r&&("/"!==r.charAt(r.length-1)&&(r+="/"),e=r+"static/plugins/@nocobase/plugin-api-keys/dist/client/")}if(!e){if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var n=window.location.pathname||"/",o=n.indexOf("/v2/");e=o>=0?n.slice(0,o+1):"/"}e&&(e=e.replace(/\/v2\/?$/,"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/@nocobase/plugin-api-keys/dist/client/"}d.p=e}(),!function(){d.r(m),d.d(m,{PluginAPIKeysClient:function(){return c}});var e=d(342);function t(e,t,r,n,o,i,u){try{var a=e[i](u),c=a.value}catch(e){r(e);return}a.done?t(c):Promise.resolve(c).then(n,o)}function r(e,t,n){return(r=u()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&o(i,r.prototype),i}).apply(null,arguments)}function n(e){return(n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(e){var t="function"==typeof Map?new Map:void 0;return(i=function(e){if(null===e||-1===Function.toString.call(e).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,i)}function i(){return r(e,arguments,n(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),o(i,e)})(e)}function u(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(u=function(){return!!e})()}var a=(0,e.lazy)(function(){return d.e("252").then(d.bind(d,847))},"Configuration").Configuration,c=function(e){var r;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function i(){var e,t;if(!(this instanceof i))throw TypeError("Cannot call a class as a function");return e=i,t=arguments,e=n(e),function(e,t){var r;if(t&&("object"==((r=t)&&"u">typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,u()?Reflect.construct(e,t||[],n(this).constructor):e.apply(this,t))}return i.prototype=Object.create(e&&e.prototype,{constructor:{value:i,writable:!0,configurable:!0}}),e&&o(i,e),r=[{key:"load",value:function(){var e;return(e=function(){return function(e,t){var r,n,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},u=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),a=Object.defineProperty;return a(u,"next",{value:c(0)}),a(u,"throw",{value:c(1)}),a(u,"return",{value:c(2)}),"function"==typeof Symbol&&a(u,Symbol.iterator,{value:function(){return this}}),u;function c(a){return function(c){var l=[a,c];if(r)throw TypeError("Generator is already executing.");for(;u&&(u=0,l[0]&&(i=0)),i;)try{if(r=1,n&&(o=2&l[0]?n.return:l[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,l[1])).done)return o;switch(n=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,n=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],n=0}finally{r=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}(this,function(e){return this.pluginSettingsManager.add("api-keys",{icon:"KeyOutlined",title:this.t("API keys"),Component:a,aclSnippet:"pm.api-keys.configuration"}),[2]})},function(){var r=this,n=arguments;return new Promise(function(o,i){var u=e.apply(r,n);function a(e){t(u,o,i,a,c,"next",e)}function c(e){t(u,o,i,a,c,"throw",e)}a(void 0)})}).call(this)}}],function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(i.prototype,r),i}(i(e.Plugin));m.default=c}(),m}()});
@@ -8,9 +8,9 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "2.1.0-alpha.13",
12
- "@nocobase/database": "2.1.0-alpha.13",
13
- "@nocobase/server": "2.1.0-alpha.13",
11
+ "@nocobase/client": "2.1.0-alpha.15",
12
+ "@nocobase/database": "2.1.0-alpha.15",
13
+ "@nocobase/server": "2.1.0-alpha.15",
14
14
  "@formily/react": "2.3.7",
15
15
  "ahooks": "3.7.8",
16
16
  "antd": "5.24.2",
@@ -18,5 +18,5 @@ module.exports = {
18
18
  "react": "18.2.0",
19
19
  "@formily/shared": "2.3.7",
20
20
  "react-i18next": "11.18.6",
21
- "@nocobase/actions": "2.1.0-alpha.13"
21
+ "@nocobase/actions": "2.1.0-alpha.15"
22
22
  };
@@ -0,0 +1,10 @@
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
+ import Application from '@nocobase/server';
10
+ export default function generateAPIKeyCommand(app: Application): void;
@@ -0,0 +1,40 @@
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 __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var generate_exports = {};
28
+ __export(generate_exports, {
29
+ default: () => generateAPIKeyCommand
30
+ });
31
+ module.exports = __toCommonJS(generate_exports);
32
+ function generateAPIKeyCommand(app) {
33
+ app.command("generate-api-key").preload().requiredOption("-n, --name <name>", "The name of the API key").requiredOption("-r, --role <roleName>", "The role of the API key").requiredOption("-u, --username <username>", "The username of the API key").option("-e, --expires-in [expiresIn]", "The expiration time of the API key", "30d").action(async (options) => {
34
+ const plugin = app.pm.get("api-keys");
35
+ const token = await plugin.generateAPIKey(options);
36
+ console.log("-----BEGIN API KEY-----");
37
+ console.log(token);
38
+ console.log("-----END API KEY-----");
39
+ });
40
+ }
@@ -9,6 +9,7 @@
9
9
  import { Plugin } from '@nocobase/server';
10
10
  export declare class PluginAPIKeysServer extends Plugin {
11
11
  resourceName: string;
12
+ generateAPIKey(values: any): Promise<string>;
12
13
  beforeLoad(): Promise<void>;
13
14
  load(): Promise<void>;
14
15
  }
@@ -34,6 +34,37 @@ var import_server = require("@nocobase/server");
34
34
  var import_api_keys = require("./actions/api-keys");
35
35
  class PluginAPIKeysServer extends import_server.Plugin {
36
36
  resourceName = "apiKeys";
37
+ async generateAPIKey(values) {
38
+ const { name, username, role: roleName, expiresIn } = values;
39
+ const user = await this.db.getRepository("users").findOne({
40
+ filter: {
41
+ username
42
+ }
43
+ });
44
+ if (!user) {
45
+ throw new Error("User not found");
46
+ }
47
+ const userId = user.id;
48
+ const repository = this.db.getRepository("users.roles", userId);
49
+ const role = await repository.findOne({
50
+ filter: {
51
+ name: roleName
52
+ }
53
+ });
54
+ if (!role) {
55
+ throw new Error("Role not found");
56
+ }
57
+ const token = this.app.authManager.jwt.sign({ userId, roleName }, { expiresIn });
58
+ await this.db.getRepository(this.resourceName).create({
59
+ values: {
60
+ name,
61
+ roleName,
62
+ token,
63
+ expiresIn
64
+ }
65
+ });
66
+ return token;
67
+ }
37
68
  async beforeLoad() {
38
69
  this.app.resourcer.define({
39
70
  name: this.resourceName,
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "description": "Allows users to use API key to access application's HTTP API",
7
7
  "description.ru-RU": "Позволяет пользователям использовать API ключ для доступа к HTTP API приложения",
8
8
  "description.zh-CN": "允许用户使用 API 密钥访问应用的 HTTP API",
9
- "version": "2.1.0-alpha.13",
9
+ "version": "2.1.0-alpha.15",
10
10
  "license": "Apache-2.0",
11
11
  "main": "./dist/server/index.js",
12
12
  "homepage": "https://docs.nocobase.com/handbook/api-keys",
@@ -35,5 +35,5 @@
35
35
  "@nocobase/test": "2.x",
36
36
  "@nocobase/utils": "2.x"
37
37
  },
38
- "gitHead": "2807a8948412d9c235115a31a81a66f7c82dd173"
38
+ "gitHead": "7c86e75b0af4b9f532c8ebf5ef96a7423b0ab60e"
39
39
  }