@nocobase/plugin-api-keys 2.1.0-beta.2 → 2.1.0-beta.20

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/README.md CHANGED
@@ -1,17 +1,24 @@
1
1
  # NocoBase
2
2
 
3
3
  <video width="100%" controls>
4
- <source src="https://static-docs.nocobase.com/NocoBase0510.mp4" type="video/mp4">
4
+ <source src="https://github.com/user-attachments/assets/4d11a87b-00e2-48f3-9bf7-389d21072d13" type="video/mp4">
5
5
  </video>
6
6
 
7
+ <p align="center">
8
+ <a href="https://trendshift.io/repositories/4112" target="_blank"><img src="https://trendshift.io/api/badge/repositories/4112" alt="nocobase%2Fnocobase | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
9
+ <a href="https://www.producthunt.com/posts/nocobase?embed=true&utm_source=badge-top-post-topic-badge&utm_medium=badge&utm_souce=badge-nocobase" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/top-post-topic-badge.svg?post_id=456520&theme=light&period=weekly&topic_id=267" alt="NocoBase - Scalability&#0045;first&#0044;&#0032;open&#0045;source&#0032;no&#0045;code&#0032;platform | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
10
+ </p>
7
11
 
8
12
  ## What is NocoBase
9
13
 
10
- NocoBase is a scalability-first, open-source no-code development platform.
11
- Instead of investing years of time and millions of dollars in research and development, deploy NocoBase in a few minutes and you'll have a private, controllable, and extremely scalable no-code development platform!
14
+ NocoBase is the most extensible AI-powered no-code platform.
15
+ Total control. Infinite extensibility. AI collaboration.
16
+ Enable your team to adapt quickly and cut costs dramatically.
17
+ No years of development. No millions wasted.
18
+ Deploy NocoBase in minutes — and take control of everything.
12
19
 
13
20
  Homepage:
14
- https://www.nocobase.com/
21
+ https://www.nocobase.com/
15
22
 
16
23
  Online Demo:
17
24
  https://demo.nocobase.com/new
@@ -19,12 +26,74 @@ https://demo.nocobase.com/new
19
26
  Documents:
20
27
  https://docs.nocobase.com/
21
28
 
22
- Commericial license & plugins:
23
- https://www.nocobase.com/en/commercial
29
+ Forum:
30
+ https://forum.nocobase.com/
24
31
 
25
- License agreement:
26
- https://www.nocobase.com/en/agreement
32
+ Use Cases:
33
+ https://www.nocobase.com/en/blog/tags/customer-stories
27
34
 
35
+ ## Release Notes
28
36
 
29
- ## Contact Us:
30
- hello@nocobase.com
37
+ Our [blog](https://www.nocobase.com/en/blog/timeline) is regularly updated with release notes and provides a weekly summary.
38
+
39
+ ## Distinctive features
40
+
41
+ ### 1. Data model-driven, not form/table–driven
42
+
43
+ Instead of being constrained by forms or tables, NocoBase adopts a data model–driven approach, separating data structure from user interface to unlock unlimited possibilities.
44
+
45
+ - UI and data structure are fully decoupled
46
+ - Multiple blocks and actions can be created for the same table or record in any quantity or form
47
+ - Supports the main database, external databases, and third-party APIs as data sources
48
+
49
+ ![model](https://static-docs.nocobase.com/model.png)
50
+
51
+ ### 2. AI employees, integrated into your business systems
52
+ Unlike standalone AI demos, NocoBase allows you to embed AI capabilities seamlessly into your interfaces, workflows, and data context, making AI truly useful in real business scenarios.
53
+
54
+ - Define AI employees for roles such as translator, analyst, researcher, or assistant
55
+ - Seamless AI–human collaboration in interfaces and workflows
56
+ - Ensure AI usage is secure, transparent, and customizable for your business needs
57
+
58
+ ![AI-employee](https://static-docs.nocobase.com/ai-employee-home.png)
59
+
60
+ ### 3. What you see is what you get, incredibly easy to use
61
+
62
+ While enabling the development of complex business systems, NocoBase keeps the experience simple and intuitive.
63
+
64
+ - One-click switch between usage mode and configuration mode
65
+ - Pages serve as a canvas to arrange blocks and actions, similar to Notion
66
+ - Configuration mode is designed for ordinary users, not just programmers
67
+
68
+ ![wysiwyg](https://static-docs.nocobase.com/wysiwyg.gif)
69
+
70
+ ### 4. Everything is a plugin, designed for extension
71
+ Adding more no-code features will never cover every business case. NocoBase is built for extension through its plugin-based microkernel architecture.
72
+
73
+ - All functionalities are plugins, similar to WordPress
74
+ - Plugins are ready to use upon installation
75
+ - Pages, blocks, actions, APIs, and data sources can all be extended through custom plugins
76
+
77
+ ![plugins](https://static-docs.nocobase.com/plugins.png)
78
+
79
+ ## Installation
80
+
81
+ NocoBase supports three installation methods:
82
+
83
+ - <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/docker-compose">Installing With Docker (👍Recommended)</a>
84
+
85
+ Suitable for no-code scenarios, no code to write. When upgrading, just download the latest image and reboot.
86
+
87
+ - <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/create-nocobase-app">Installing from create-nocobase-app CLI</a>
88
+
89
+ The business code of the project is completely independent and supports low-code development.
90
+
91
+ - <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/git-clone">Installing from Git source code</a>
92
+
93
+ If you want to experience the latest unreleased version, or want to participate in the contribution, you need to make changes and debug on the source code, it is recommended to choose this installation method, which requires a high level of development skills, and if the code has been updated, you can git pull the latest code.
94
+
95
+ ## How NocoBase works
96
+
97
+ <video width="100%" controls>
98
+ <source src="https://github.com/user-attachments/assets/8d183b44-9bb5-4792-b08f-bc08fe8dfaaf" type="video/mp4">
99
+ </video>
@@ -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
+
10
+ "use strict";(self.webpackChunk_nocobase_plugin_api_keys=self.webpackChunk_nocobase_plugin_api_keys||[]).push([["252"],{847:function(e,t,r){r.r(t),r.d(t,{Configuration:function(){return D}});var n,o,a,l=r(342),i=r(155),c=r.n(i),u=r(230),s=r(625),p=r(59),m=r(185),y=r.n(m),d=r(953),f="@nocobase/plugin-api-keys";function b(){return(0,d.useTranslation)([f,"client"],{nsMode:"fallback"})}function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function x(){var e,t,r=(e=["\n width: 100%;\n & > .ant-space-item {\n flex: 1;\n }\n"],t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}})));return x=function(){return r},r}var g=y()().add(1,"days"),h=(0,l.css)(x()),w=(0,u.connect)(function(e){var t,r,n,o=e.onChange,a=function(e){if(Array.isArray(e))return e}(t=(0,s.useBoolean)())||function(e){var t,r,n=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o=[],a=!0,l=!1;try{for(n=n.call(e);!(a=(t=n.next()).done)&&(o.push(t.value),2!==o.length);a=!0);}catch(e){l=!0,r=e}finally{try{a||null==n.return||n.return()}finally{if(l)throw r}}return o}}(t)||function(e){if(e){if("string"==typeof e)return v(e,2);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return v(e,2)}}(t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),l=a[0],i=a[1],u=i.toggle,m=i.setFalse;return c().createElement(p.Space,{className:h},c().createElement(p.Select,(r=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({},e),n=n={value:l?"custom":e.value,onChange:function(e){if("custom"===e)return o("1d"),u();m(),o(e)}},Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(n)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))}),r)),l?c().createElement(p.DatePicker,{disabledDate:function(e){return e.isSameOrBefore()},defaultValue:g,onChange:function(e){e=e.millisecond(0).second(0);var t=y()().millisecond(0).second(0);o("".concat(e.diff(t,"d"),"d"))},showToday:!1,allowClear:!1}):null)},(0,u.mapProps)({dataSource:"options"}),(0,u.mapReadPretty)(function(){var e=(0,l.useRecord)(),t=e.expiresIn,r=e.createdAt,n=b().t,o=(0,i.useMemo)(function(){return"never"===t?n("Never expires"):y()(r).add((null==t?void 0:t.replace("d",""))||0,"days").format("YYYY-MM-DD HH:mm:ss")},[r,t]);return c().createElement(p.Typography.Text,null,o)})),A=r(166);function C(e){return"{{t('".concat(e,"', { ns: '").concat(f,"', nsMode: 'fallback' })}}")}var O={dumpRules:{group:"user"},migrationRules:["schema-only"],shared:!0,name:"apiKeys",sortable:"sort",createdBy:!0,updatedAt:!1,updatedBy:!1,logging:!0,fields:[{name:"id",type:"bigInt",autoIncrement:!0,primaryKey:!0,allowNull:!1,interface:"id"},{type:"string",name:"name",interface:"input",uiSchema:{type:"string",title:'{{t("name")}}',"x-component":"Input"}},{interface:"obo",type:"belongsTo",name:"role",target:"roles",foreignKey:"roleName",uiSchema:{type:"object",title:'{{t("Roles")}}',"x-component":"Select","x-component-props":{fieldNames:{label:"title",value:"name"},objectValue:!0,options:"{{ currentRoles }}"}}},{name:"expiresIn",type:"string",uiSchema:{type:"string",title:C("Expires"),"x-component":"ExpiresSelect",enum:[{label:C("1 Day"),value:"1d"},{label:C("7 Days"),value:"7d"},{label:C("30 Days"),value:"30d"},{label:C("90 Days"),value:"90d"},{label:C("Custom"),value:"custom"},{label:C("Never"),value:"never"}]}},{name:"token",type:"string",hidden:!0}]};function k(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function S(e,t,r,n,o,a,l){try{var i=e[a](l),c=i.value}catch(e){r(e);return}i.done?t(c):Promise.resolve(c).then(n,o)}function j(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){S(a,n,o,l,i,"next",e)}function i(e){S(a,n,o,l,i,"throw",e)}l(void 0)})}}function P(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:c(0)}),i(l,"throw",{value:c(1)}),i(l,"return",{value:c(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function c(i){return function(c){var u=[i,c];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,u[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,n=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],n=0}finally{r=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var I=p.Modal.useModal,T={type:"object",properties:{configuration:{type:"void","x-decorator":"TableBlockProvider","x-decorator-props":{collection:O,resource:"apiKeys",action:"list",params:{pageSize:20,appends:["role"],sort:["-createdAt"]},rowKey:"name",showIndex:!0},"x-component":"CardItem",properties:(n={actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:"var(--nb-spacing)"}},properties:{create:{type:"void","x-action":"create",title:C("Add API key"),"x-component":"Action","x-component-props":{icon:"PlusOutlined",openMode:"drawer",type:"primary"},properties:{drawer:{type:"void",title:C("Add API key"),"x-decorator":"Form","x-component":"Action.Modal","x-component-props":{maskClosable:!1,style:{maxWidth:"520px",width:"100%"}},properties:{name:{type:"string",title:C("Key name"),required:!0,"x-component":"CollectionField","x-decorator":"FormItem"},role:{type:"string",title:C("Role"),required:!0,"x-decorator-props":{tooltip:C("Allow only your own roles to be selected")},"x-collection-field":"apiKeys.role","x-component":"CollectionField","x-decorator":"FormItem"},expiresIn:{type:"string",title:C("Expiration"),required:!0,"x-component":"CollectionField","x-decorator":"FormItem",default:"30d"},footer:{type:"void","x-component":"Action.Modal.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:function(){var e,t=(0,u.useForm)(),r=(0,l.useActionContext)().setVisible,n=(0,l.useBlockRequestContext)(),o=n.resource,a=n.service,i=b().t,s=function(e){if(Array.isArray(e))return e}(e=I())||function(e){var t,r,n=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o=[],a=!0,l=!1;try{for(n=n.call(e);!(a=(t=n.next()).done)&&(o.push(t.value),2!==o.length);a=!0);}catch(e){l=!0,r=e}finally{try{a||null==n.return||n.return()}finally{if(l)throw r}}return o}}(e)||function(e){if(e){if("string"==typeof e)return k(e,2);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return k(e,2)}}(e)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),m=s[0];return{run:function(){return j(function(){var e,n,l;return P(this,function(u){switch(u.label){case 0:return[4,t.submit()];case 1:return u.sent(),[4,o.create({values:t.values})];case 2:return l=u.sent(),m.success({title:i("API key created successfully"),onOk:function(){t.reset(),r(!1)},content:c().createElement(p.Space,{direction:"vertical"},c().createElement(p.Alert,{message:i("Make sure to copy your personal access key now as you will not be able to see this again."),type:"warning"}),c().createElement(p.Typography.Text,{copyable:!0},null==(n=l.data)||null==(e=n.data)?void 0:e.token))}),null==a||a.refresh(),[2]}})})()},element:s[1]}}}}}}}}},"x-align":"right"}}}},o=(0,A.uid)(),a={type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"id"},properties:{column1:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:C("Key name"),properties:{name:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},column2:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:C("Role"),properties:{role:{type:"string","x-collection-field":"apiKeys.role","x-component":"CollectionField","x-component-props":{enableLink:!1},"x-read-pretty":!0}}},column3:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:C("Expiration"),properties:{expiresIn:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},column4:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:C("Created at"),properties:{createdAt:{type:"date","x-component":"DatePicker","x-component-props":{format:"YYYY-MM-DD HH:mm:ss"},"x-read-pretty":!0}}},actionColumn:{type:"void",title:'{{ t("Actions") }}',"x-action-column":"actions","x-decorator":"TableV2.Column.ActionBar","x-component":"TableV2.Column",properties:{columnActions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action.Link","x-component-props":{confirm:{title:C("Delete API key"),content:"{{t('Are you sure you want to delete it?')}}"},useAction:function(){var e=(0,l.useRecord)(),t=(0,l.useBlockRequestContext)(),r=t.resource,n=t.service;return{run:function(){return j(function(){return P(this,function(t){switch(t.label){case 0:return[4,r.destroy({filterByTk:e.id})];case 1:return t.sent(),n.refresh(),[2]}})})()}}}}}}}}}}},o in n?Object.defineProperty(n,o,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[o]=a,n)}}},D=function(){var e=(0,l.useCurrentRoles)().filter(function(e){return"__union__"!==e.name});return c().createElement(l.SchemaComponentOptions,{scope:{currentRoles:e},components:{ExpiresSelect:w}},c().createElement(l.NocoBaseRecursionField,{schema:T}))}}}]);
@@ -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("dayjs"),require("ahooks"),require("@formily/shared"),require("@nocobase/client"),require("react"),require("@formily/react"),require("antd"),require("react-i18next")):"function"==typeof define&&define.amd?define("@nocobase/plugin-api-keys",["dayjs","ahooks","@formily/shared","@nocobase/client","react","@formily/react","antd","react-i18next"],t):"object"==typeof exports?exports["@nocobase/plugin-api-keys"]=t(require("dayjs"),require("ahooks"),require("@formily/shared"),require("@nocobase/client"),require("react"),require("@formily/react"),require("antd"),require("react-i18next")):e["@nocobase/plugin-api-keys"]=t(e.dayjs,e.ahooks,e["@formily/shared"],e["@nocobase/client"],e.react,e["@formily/react"],e.antd,e["react-i18next"])}(self,function(e,t,n,r,o,i,u,a){return function(){var c,f,s,l,p,d,y={581:function(e){e.exports=function(e,t){return"undefined"!=typeof __deoptimization_sideEffect__&&__deoptimization_sideEffect__(e,t),t}},505:function(e){"use strict";e.exports=i},875:function(e){"use strict";e.exports=n},772:function(e){"use strict";e.exports=r},749:function(e){"use strict";e.exports=t},721:function(e){"use strict";e.exports=u},760:function(t){"use strict";t.exports=e},156:function(e){"use strict";e.exports=o},238:function(e){"use strict";e.exports=a}},b={};function h(e){var t=b[e];if(void 0!==t)return t.exports;var n=b[e]={exports:{}};return y[e](n,n.exports,h),n.exports}h.m=y,h.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return h.d(t,{a:t}),t},h.d=function(e,t){for(var n in t)h.o(t,n)&&!h.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},h.f={},h.e=function(e){return Promise.all(Object.keys(h.f).reduce(function(t,n){return h.f[n](e,t),t},[]))},h.u=function(e){return"e0d2a4a22c6932da.js"},h.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),h.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},c={},f="@nocobase/plugin-api-keys:",h.l=function(e,t,n,r){if(c[e])return void c[e].push(t);if(void 0!==n)for(var o,i,u=document.getElementsByTagName("script"),a=0;a<u.length;a++){var s=u[a];if(s.getAttribute("src")==e||s.getAttribute("data-webpack")==f+n){o=s;break}}o||(i=!0,(o=document.createElement("script")).charset="utf-8",o.timeout=120,h.nc&&o.setAttribute("nonce",h.nc),o.setAttribute("data-webpack",f+n),o.src=e),c[e]=[t];var l=function(t,n){o.onerror=o.onload=null,clearTimeout(p);var r=c[e];if(delete c[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},p=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)},h.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(s=window.__webpack_public_path__||"/").endsWith("/")||(s+="/"),h.p=s+"static/plugins/@nocobase/plugin-api-keys/dist/client/",l={909:0},h.f.j=function(e,t){var n=h.o(l,e)?l[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=l[e]=[t,r]});t.push(n[2]=r);var o=h.p+h.u(e),i=Error();h.l(o,function(t){if(h.o(l,e)&&(0!==(n=l[e])&&(l[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;i.message="Loading chunk "+e+" failed.\n("+r+": "+o+")",i.name="ChunkLoadError",i.type=r,i.request=o,n[1](i)}},"chunk-"+e,e)}},p=function(e,t){var n,r,o=t[0],i=t[1],u=t[2],a=0;if(o.some(function(e){return 0!==l[e]})){for(n in i)h.o(i,n)&&(h.m[n]=i[n]);u&&u(h)}for(e&&e(t);a<o.length;a++)r=o[a],h.o(l,r)&&l[r]&&l[r][0](),l[r]=0},(d=self.webpackChunk_nocobase_plugin_api_keys=self.webpackChunk_nocobase_plugin_api_keys||[]).forEach(p.bind(null,0)),d.push=p.bind(null,d.push.bind(d));var v={};return!function(){"use strict";h.r(v),h.d(v,{PluginAPIKeysClient:function(){return f}});var e=h(772),t=h(581);function n(e,t,n,r,o,i,u){try{var a=e[i](u),c=a.value}catch(e){n(e);return}a.done?t(c):Promise.resolve(c).then(r,o)}function r(e,t,n){return(r=a()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&i(o,n.prototype),o}).apply(null,arguments)}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(e){var t="function"==typeof Map?new Map:void 0;return(u=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,n)}function n(){return r(e,arguments,o(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),i(n,e)})(e)}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(a=function(){return!!e})()}var c=(0,e.lazy)(function(){return t("imported_-138s8db_component",h.e("152").then(h.bind(h,764)))},"Configuration").Configuration,f=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=o(e),function(e,t){var n;if(t&&("object"==((n=t)&&"undefined"!=typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,a()?Reflect.construct(e,t||[],o(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&i(r,e),t=[{key:"load",value:function(){var e,t=this;return(e=function(){return function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){var c=[i,a];if(n)throw TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=t.call(e,u)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(e){return t.pluginSettingsManager.add("api-keys",{icon:"KeyOutlined",title:t.t("API keys"),Component:c,aclSnippet:"pm.api-keys.configuration"}),[2]})},function(){var t=this,r=arguments;return new Promise(function(o,i){var u=e.apply(t,r);function a(e){n(u,o,i,a,c,"next",e)}function c(e){n(u,o,i,a,c,"throw",e)}a(void 0)})})()}}],function(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)}}(r.prototype,t),r}(u(e.Plugin));v.default=f}(),v}()});
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""+e+".d5ae25fe436c24c0.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-beta.2",
12
- "@nocobase/database": "2.1.0-beta.2",
13
- "@nocobase/server": "2.1.0-beta.2",
11
+ "@nocobase/client": "2.1.0-beta.20",
12
+ "@nocobase/database": "2.1.0-beta.20",
13
+ "@nocobase/server": "2.1.0-beta.20",
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-beta.2"
21
+ "@nocobase/actions": "2.1.0-beta.20"
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,8 +6,8 @@
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-beta.2",
10
- "license": "AGPL-3.0",
9
+ "version": "2.1.0-beta.20",
10
+ "license": "Apache-2.0",
11
11
  "main": "./dist/server/index.js",
12
12
  "homepage": "https://docs.nocobase.com/handbook/api-keys",
13
13
  "homepage.ru-RU": "https://docs-ru.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": "d80433799fb4a8d59ded4d7eea114d585a137ea0"
38
+ "gitHead": "5515f27380c0c5410f7d1e5e5858364fcd838e5e"
39
39
  }
@@ -1,10 +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
- "use strict";(self.webpackChunk_nocobase_plugin_api_keys=self.webpackChunk_nocobase_plugin_api_keys||[]).push([["152"],{764:function(e,t,n){n.r(t),n.d(t,{Configuration:function(){return D}});var r,o,a,l=n(772),i=n(156),c=n.n(i),u=n(505),s=n(749),p=n(721),m=n(760),y=n.n(m),d=n(238),f="@nocobase/plugin-api-keys";function b(){return(0,d.useTranslation)([f,"client"],{nsMode:"fallback"})}function x(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 v(){var e,t,n=(e=["\n width: 100%;\n & > .ant-space-item {\n flex: 1;\n }\n"],t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}})));return v=function(){return n},n}var g=y()().add(1,"days"),h=(0,l.css)(v()),w=(0,u.connect)(function(e){var t,n,r,o=e.onChange,a=(t=(0,s.useBoolean)(),function(e){if(Array.isArray(e))return e}(t)||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),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}}(t,2)||function(e,t){if(e){if("string"==typeof e)return x(e,2);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 x(e,t)}}(t,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),l=a[0],i=a[1],u=i.toggle,m=i.setFalse;return c().createElement(p.Space,{className:h},c().createElement(p.Select,(n=function(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;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},e),r=r={value:l?"custom":e.value,onChange:function(e){if("custom"===e)return o("1d"),u();m(),o(e)}},Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(r)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(r)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(r,e))}),n)),l?c().createElement(p.DatePicker,{disabledDate:function(e){return e.isSameOrBefore()},defaultValue:g,onChange:function(e){e=e.millisecond(0).second(0);var t=y()().millisecond(0).second(0);o("".concat(e.diff(t,"d"),"d"))},showToday:!1,allowClear:!1}):null)},(0,u.mapProps)({dataSource:"options"}),(0,u.mapReadPretty)(function(){var e=(0,l.useRecord)(),t=e.expiresIn,n=e.createdAt,r=b().t,o=(0,i.useMemo)(function(){return"never"===t?r("Never expires"):y()(n).add((null==t?void 0:t.replace("d",""))||0,"days").format("YYYY-MM-DD HH:mm:ss")},[n,t]);return c().createElement(p.Typography.Text,null,o)})),A=n(875);function C(e){return"{{t('".concat(e,"', { ns: '").concat(f,"', nsMode: 'fallback' })}}")}var k={dumpRules:{group:"user"},migrationRules:["schema-only"],shared:!0,name:"apiKeys",sortable:"sort",createdBy:!0,updatedAt:!1,updatedBy:!1,logging:!0,fields:[{name:"id",type:"bigInt",autoIncrement:!0,primaryKey:!0,allowNull:!1,interface:"id"},{type:"string",name:"name",interface:"input",uiSchema:{type:"string",title:'{{t("name")}}',"x-component":"Input"}},{interface:"obo",type:"belongsTo",name:"role",target:"roles",foreignKey:"roleName",uiSchema:{type:"object",title:'{{t("Roles")}}',"x-component":"Select","x-component-props":{fieldNames:{label:"title",value:"name"},objectValue:!0,options:"{{ currentRoles }}"}}},{name:"expiresIn",type:"string",uiSchema:{type:"string",title:C("Expires"),"x-component":"ExpiresSelect",enum:[{label:C("1 Day"),value:"1d"},{label:C("7 Days"),value:"7d"},{label:C("30 Days"),value:"30d"},{label:C("90 Days"),value:"90d"},{label:C("Custom"),value:"custom"},{label:C("Never"),value:"never"}]}},{name:"token",type:"string",hidden:!0}]};function O(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 S(e,t,n,r,o,a,l){try{var i=e[a](l),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,o)}function j(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var a=e.apply(t,n);function l(e){S(a,r,o,l,i,"next",e)}function i(e){S(a,r,o,l,i,"throw",e)}l(void 0)})}}function P(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){var c=[a,i];if(n)throw TypeError("Generator is already executing.");for(;l;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,r=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){l=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){l.label=c[1];break}if(6===c[0]&&l.label<o[1]){l.label=o[1],o=c;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(c);break}o[2]&&l.ops.pop(),l.trys.pop();continue}c=t.call(e,l)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var T=p.Modal.useModal,I={type:"object",properties:{configuration:{type:"void","x-decorator":"TableBlockProvider","x-decorator-props":{collection:k,resource:"apiKeys",action:"list",params:{pageSize:20,appends:["role"],sort:["-createdAt"]},rowKey:"name",showIndex:!0},"x-component":"CardItem",properties:(r={actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:"var(--nb-spacing)"}},properties:{create:{type:"void","x-action":"create",title:C("Add API key"),"x-component":"Action","x-component-props":{icon:"PlusOutlined",openMode:"drawer",type:"primary"},properties:{drawer:{type:"void",title:C("Add API key"),"x-decorator":"Form","x-component":"Action.Modal","x-component-props":{maskClosable:!1,style:{maxWidth:"520px",width:"100%"}},properties:{name:{type:"string",title:C("Key name"),required:!0,"x-component":"CollectionField","x-decorator":"FormItem"},role:{type:"string",title:C("Role"),required:!0,"x-decorator-props":{tooltip:C("Allow only your own roles to be selected")},"x-collection-field":"apiKeys.role","x-component":"CollectionField","x-decorator":"FormItem"},expiresIn:{type:"string",title:C("Expiration"),required:!0,"x-component":"CollectionField","x-decorator":"FormItem",default:"30d"},footer:{type:"void","x-component":"Action.Modal.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:function(){var e,t=(0,u.useForm)(),n=(0,l.useActionContext)().setVisible,r=(0,l.useBlockRequestContext)(),o=r.resource,a=r.service,i=b().t,s=(e=T(),function(e){if(Array.isArray(e))return e}(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),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,2)||function(e,t){if(e){if("string"==typeof e)return O(e,2);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 O(e,t)}}(e,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),m=s[0];return{run:function(){return j(function(){var e,r,l;return P(this,function(u){switch(u.label){case 0:return[4,t.submit()];case 1:return u.sent(),[4,o.create({values:t.values})];case 2:return l=u.sent(),m.success({title:i("API key created successfully"),onOk:function(){t.reset(),n(!1)},content:c().createElement(p.Space,{direction:"vertical"},c().createElement(p.Alert,{message:i("Make sure to copy your personal access key now as you will not be able to see this again."),type:"warning"}),c().createElement(p.Typography.Text,{copyable:!0},null==(r=l.data)||null==(e=r.data)?void 0:e.token))}),null==a||a.refresh(),[2]}})})()},element:s[1]}}}}}}}}},"x-align":"right"}}}},o=(0,A.uid)(),a={type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"id"},properties:{column1:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:C("Key name"),properties:{name:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},column2:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:C("Role"),properties:{role:{type:"string","x-collection-field":"apiKeys.role","x-component":"CollectionField","x-component-props":{enableLink:!1},"x-read-pretty":!0}}},column3:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:C("Expiration"),properties:{expiresIn:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},column4:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:C("Created at"),properties:{createdAt:{type:"date","x-component":"DatePicker","x-component-props":{format:"YYYY-MM-DD HH:mm:ss"},"x-read-pretty":!0}}},actionColumn:{type:"void",title:'{{ t("Actions") }}',"x-action-column":"actions","x-decorator":"TableV2.Column.ActionBar","x-component":"TableV2.Column",properties:{columnActions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action.Link","x-component-props":{confirm:{title:C("Delete API key"),content:"{{t('Are you sure you want to delete it?')}}"},useAction:function(){var e=(0,l.useRecord)(),t=(0,l.useBlockRequestContext)(),n=t.resource,r=t.service;return{run:function(){return j(function(){return P(this,function(t){switch(t.label){case 0:return[4,n.destroy({filterByTk:e.id})];case 1:return t.sent(),r.refresh(),[2]}})})()}}}}}}}}}}},o in r?Object.defineProperty(r,o,{value:a,enumerable:!0,configurable:!0,writable:!0}):r[o]=a,r)}}},D=function(){var e=(0,l.useCurrentRoles)().filter(function(e){return"__union__"!==e.name});return c().createElement(l.SchemaComponentOptions,{scope:{currentRoles:e},components:{ExpiresSelect:w}},c().createElement(l.NocoBaseRecursionField,{schema:I}))}}}]);