@nocobase/plugin-api-keys 2.1.0-alpha.4 → 2.1.0-alpha.40
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/LICENSE +201 -661
- package/README.md +79 -10
- package/client-v2.d.ts +2 -0
- package/client-v2.js +1 -0
- package/dist/client/252.d5ae25fe436c24c0.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/849.3f8b976beb7f19c9.js +10 -0
- package/dist/client-v2/index.d.ts +9 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/client-v2/locale.d.ts +10 -0
- package/dist/client-v2/pages/ApiKeysPage.d.ts +59 -0
- package/dist/client-v2/pages/ExpiresField.d.ts +30 -0
- package/dist/client-v2/plugin.d.ts +14 -0
- package/dist/externalVersion.js +7 -4
- package/dist/server/commands/generate.d.ts +10 -0
- package/dist/server/commands/generate.js +40 -0
- package/dist/server/plugin.d.ts +1 -0
- package/dist/server/plugin.js +31 -0
- package/package.json +5 -3
- package/dist/client/e0d2a4a22c6932da.js +0 -10
package/README.md
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
# NocoBase
|
|
2
2
|
|
|
3
3
|
<video width="100%" controls>
|
|
4
|
-
|
|
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-first, open-source no-code 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
|
|
11
|
-
|
|
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
|
-
|
|
23
|
-
https://
|
|
29
|
+
Forum:
|
|
30
|
+
https://forum.nocobase.com/
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
https://www.nocobase.com/en/
|
|
32
|
+
Use Cases:
|
|
33
|
+
https://www.nocobase.com/en/blog/tags/customer-stories
|
|
27
34
|
|
|
35
|
+
## Release Notes
|
|
28
36
|
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+

|
|
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
|
+

|
|
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
|
+

|
|
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
|
+

|
|
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>
|
package/client-v2.d.ts
ADDED
package/client-v2.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/client-v2/index.js');
|
|
@@ -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}))}}}]);
|
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("
|
|
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}()});
|
|
@@ -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
|
+
(self.webpackChunk_nocobase_plugin_api_keys_client_v2=self.webpackChunk_nocobase_plugin_api_keys_client_v2||[]).push([["849"],{153:function(e){e.exports=function(e,t){t.prototype.isSameOrBefore=function(e,t){return this.isSame(e,t)||this.isBefore(e,t)}}},648:function(e,t,n){"use strict";n.r(t),n.d(t,{submitApiKeyForm:function(){return k},default:function(){return S},deleteApiKey:function(){return A}});var r=n(375),l=n(485),a=n(694),o=n(625),u=n(59),i=n(185),c=n.n(i),s=n(155),f=n.n(s);function d(){var e=(0,a.useFlowEngine)();return function(t,n){return e.context.t(t,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}({ns:["@nocobase/plugin-api-keys","client"]},n))}}var m=n(153),p=n.n(m);function y(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(e){var t,n=e.value,r=e.onChange,l=e.options,a=function(e){if(Array.isArray(e))return e}(t=(0,o.useBoolean)(!1))||function(e){var t,n,r=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var l=[],a=!0,o=!1;try{for(r=r.call(e);!(a=(t=r.next()).done)&&(l.push(t.value),2!==l.length);a=!0);}catch(e){o=!0,n=e}finally{try{a||null==r.return||r.return()}finally{if(o)throw n}}return l}}(t)||function(e){if(e){if("string"==typeof e)return y(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 y(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.")}(),i=a[0],s=a[1],d=s.toggle,m=s.setFalse;return f().createElement(u.Space,{style:{width:"100%"},styles:{item:{flex:1}}},f().createElement(u.Select,{style:{width:"100%"},options:l,value:i?"custom":n,onChange:function(e){if("custom"===e){null==r||r("1d"),d();return}m(),null==r||r(e)}}),i?f().createElement(u.DatePicker,{style:{width:"100%"},disabledDate:function(e){return e.isSameOrBefore(c()())},defaultValue:c()().add(1,"days"),onChange:function(e){e&&(null==r||r(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c()(),n=e.millisecond(0).second(0),r=t.millisecond(0).second(0);return"".concat(n.diff(r,"d"),"d")}(e)))},allowClear:!1}):null)}function b(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 h(e,t,n,r,l,a,o){try{var u=e[a](o),i=u.value}catch(e){n(e);return}u.done?t(i):Promise.resolve(i).then(r,l)}function g(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){h(a,r,l,o,u,"next",e)}function u(e){h(a,r,l,o,u,"throw",e)}o(void 0)})}}function w(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,u=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){u=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(u)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return b(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 b(e,t)}}(e,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.")}()}function E(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(o,"next",{value:i(0)}),u(o,"throw",{value:i(1)}),u(o,"return",{value:i(2)}),"function"==typeof Symbol&&u(o,Symbol.iterator,{value:function(){return this}}),o;function i(u){return function(i){var c=[u,i];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}function k(e){return g(function(){var t,n,r;return E(this,function(l){switch(l.label){case 0:return[4,e.resource.create({values:e.values})];case 1:return r=l.sent(),e.onCreated(null==r||null==(n=r.data)||null==(t=n.data)?void 0:t.token),[2]}})})()}function A(e){return g(function(){return E(this,function(t){switch(t.label){case 0:return[4,e.resource.destroy({filterByTk:e.filterByTk})];case 1:return t.sent(),e.onDeleted(),[2]}})})()}function x(e){var t,n=e.onCreated,r=d(),o=(0,a.useFlowContext)(),i=(0,a.useFlowView)(),c=[{label:(t=d())("1 Day"),value:"1d"},{label:t("7 Days"),value:"7d"},{label:t("30 Days"),value:"30d"},{label:t("90 Days"),value:"90d"},{label:t("Custom"),value:"custom"},{label:t("Never"),value:"never"}],m=(0,l.useCurrentRoles)(),p=w(u.Form.useForm(),1)[0],y=w((0,s.useState)(!1),2),b=y[0],h=y[1],A=(0,s.useMemo)(function(){return o.api.resource("apiKeys")},[o.api]),x=(0,s.useCallback)(function(){return g(function(){var e;return E(this,function(t){switch(t.label){case 0:return[4,p.validateFields()];case 1:e=t.sent(),h(!0),t.label=2;case 2:return t.trys.push([2,,5,6]),[4,k({values:{name:e.name,role:e.role?{name:e.role}:void 0,expiresIn:e.expiresIn},resource:A,onCreated:function(e){p.resetFields(),n(e)}})];case 3:return t.sent(),[4,i.close()];case 4:return t.sent(),[3,6];case 5:return h(!1),[7];case 6:return[2]}})})()},[p,n,A,i]);return f().createElement(f().Fragment,null,f().createElement(u.Form,{form:p,layout:"vertical",initialValues:{expiresIn:"30d"}},f().createElement(u.Form.Item,{name:"name",label:r("Key name"),rules:[{required:!0,message:r("The field value is required")}]},f().createElement(u.Input,null)),f().createElement(u.Form.Item,{name:"role",label:r("Role"),tooltip:r("Allow only your own roles to be selected"),rules:[{required:!0,message:r("The field value is required")}]},f().createElement(u.Select,{fieldNames:{label:"title",value:"name"},options:m})),f().createElement(u.Form.Item,{name:"expiresIn",label:r("Expiration"),rules:[{required:!0,message:r("The field value is required")}]},f().createElement(v,{options:c}))),i.Footer?f().createElement(i.Footer,null,f().createElement(u.Space,null,f().createElement(u.Button,{onClick:function(){return g(function(){return E(this,function(e){return[2,i.close()]})})()}},r("Cancel")),f().createElement(u.Button,{type:"primary",loading:b,onClick:x},r("Submit")))):null)}c().extend(p());var S=function(){var e=d(),t=(0,a.useFlowContext)(),n=(0,a.useFlowEngine)(),i=u.theme.useToken().token,m=u.App.useApp().modal,p=(0,s.useMemo)(function(){return t.api.resource("apiKeys")},[t.api]),y=(0,o.useRequest)(function(){return g(function(){var e,n;return E(this,function(r){switch(r.label){case 0:return[4,t.api.request({url:"apiKeys:list",method:"get",params:{pageSize:20,appends:["role"],sort:["-createdAt"]},skipNotify:!0})];case 1:return[2,null!=(e=null==(n=r.sent())?void 0:n.data)?e:{data:[]}]}})})()}),v=y.data,b=y.loading,h=(0,s.useMemo)(function(){var e=null==v?void 0:v.data;return Array.isArray(e)?e:[]},[v]),w=(0,s.useMemo)(function(){var e,t,n,r=null==v?void 0:v.meta;return!!r&&{total:null!=(e=r.count)?e:h.length,pageSize:null!=(t=r.pageSize)?t:20,current:null!=(n=r.page)?n:1}},[v,h.length]),k=(0,s.useCallback)(function(t){m.confirm({title:e("Delete API key"),content:e("Are you sure you want to delete it?"),onOk:function(){return g(function(){return E(this,function(e){switch(e.label){case 0:return[4,A({resource:p,filterByTk:t.id,onDeleted:function(){return y.refresh()}})];case 1:return e.sent(),[2]}})})()}})},[y,m,p,e]),S=(0,s.useCallback)(function(){t.viewer.dialog({title:e("Add API key"),width:520,maskClosable:!1,closable:!0,content:function(){return f().createElement(x,{onCreated:function(t){y.refresh(),m.success({title:e("API key created successfully"),content:f().createElement(u.Space,{direction:"vertical",style:{width:"100%"}},f().createElement(u.Alert,{type:"warning",message:e("Make sure to copy your personal access key now as you will not be able to see this again.")}),f().createElement(u.Typography.Text,{copyable:!0},t))})}})}})},[t.viewer,y,m,e]),C=e("Never expires"),I=(0,s.useMemo)(function(){return[{title:e("Key name"),dataIndex:"name",ellipsis:!0},{title:e("Role"),dataIndex:["role","title"],render:function(e,t){var r,l,a=null==(l=t.role)?void 0:l.title;return a?f().createElement(u.Tag,null,n.context.t(a)):null!=(r=t.roleName)?r:"-"}},{title:e("Expiration"),render:function(e,t){var n={expiresIn:t.expiresIn,createdAt:t.createdAt};if("never"===n.expiresIn)return C;var r,l=parseInt(String(null!=(r=n.expiresIn)?r:"").replace("d",""),10)||0;return n.createdAt?c()(n.createdAt).add(l,"days").format("YYYY-MM-DD HH:mm:ss"):""}},{title:e("Created at"),dataIndex:"createdAt",render:function(e){return e?c()(e).format("YYYY-MM-DD HH:mm:ss"):"-"}},{title:e("Actions"),width:160,render:function(t,n){return f().createElement("a",{onClick:function(){return k(n)}},e("Delete"))}}]},[n,k,C,e]);return f().createElement(u.Card,null,f().createElement(u.Flex,{justify:"flex-end",style:{marginBottom:i.marginMD}},f().createElement(u.Space,null,f().createElement(u.Button,{icon:f().createElement(r.ReloadOutlined,null),onClick:function(){return y.refresh()}},e("Refresh")),f().createElement(u.Button,{type:"primary",icon:f().createElement(r.PlusOutlined,null),onClick:S},e("Add API key")))),f().createElement(l.Table,{rowKey:"id",loading:b,dataSource:h,columns:I,pagination:w}))}}}]);
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
export { default } from './plugin';
|
|
@@ -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
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("ahooks"),require("@nocobase/client-v2"),require("dayjs"),require("react"),require("antd"),require("@ant-design/icons"),require("@nocobase/flow-engine")):"function"==typeof define&&define.amd?define("@nocobase/plugin-api-keys/client-v2",["ahooks","@nocobase/client-v2","dayjs","react","antd","@ant-design/icons","@nocobase/flow-engine"],t):"object"==typeof exports?exports["@nocobase/plugin-api-keys/client-v2"]=t(require("ahooks"),require("@nocobase/client-v2"),require("dayjs"),require("react"),require("antd"),require("@ant-design/icons"),require("@nocobase/flow-engine")):e["@nocobase/plugin-api-keys/client-v2"]=t(e.ahooks,e["@nocobase/client-v2"],e.dayjs,e.react,e.antd,e["@ant-design/icons"],e["@nocobase/flow-engine"])}(self,function(e,t,n,r,o,i,a){return function(){"use strict";var u,c,l,s={375:function(e){e.exports=i},485:function(e){e.exports=t},694:function(e){e.exports=a},625:function(t){t.exports=e},59:function(e){e.exports=o},185:function(e){e.exports=n},155:function(e){e.exports=r}},p={};function f(e){var t=p[e];if(void 0!==t)return t.exports;var n=p[e]={exports:{}};return s[e].call(n.exports,n,n.exports,f),n.exports}f.m=s,f.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(t,{a:t}),t},f.d=function(e,t){for(var n in t)f.o(t,n)&&!f.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},f.f={},f.e=function(e){return Promise.all(Object.keys(f.f).reduce(function(t,n){return f.f[n](e,t),t},[]))},f.u=function(e){return""+e+".3f8b976beb7f19c9.js"},f.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),f.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},d={},f.l=function(e,t,n,r){if(d[e])return void d[e].push(t);if(void 0!==n)for(var o,i,a=document.getElementsByTagName("script"),u=0;u<a.length;u++){var c=a[u];if(c.getAttribute("src")==e||c.getAttribute("data-rspack")=="@nocobase/plugin-api-keys/client-v2:"+n){o=c;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,f.nc&&o.setAttribute("nonce",f.nc),o.setAttribute("data-rspack","@nocobase/plugin-api-keys/client-v2:"+n),o.src=e),d[e]=[t];var l=function(t,n){o.onerror=o.onload=null,clearTimeout(s);var r=d[e];if(delete d[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},s=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)},f.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.g.importScripts&&(b=f.g.location+"");var d,b,y=f.g.document;if(!b&&y&&(y.currentScript&&"SCRIPT"===y.currentScript.tagName.toUpperCase()&&(b=y.currentScript.src),!b)){var v=y.getElementsByTagName("script");if(v.length)for(var h=v.length-1;h>-1&&(!b||!/^http(s?):/.test(b));)b=v[h--].src}if(!b)throw Error("Automatic publicPath is not supported in this browser");f.p=b.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),u={889:0},f.f.j=function(e,t){var n=f.o(u,e)?u[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=u[e]=[t,r]});t.push(n[2]=r);var o=f.p+f.u(e),i=Error();f.l(o,function(t){if(f.o(u,e)&&(0!==(n=u[e])&&(u[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)}},c=function(e,t){var n,r,o=t[0],i=t[1],a=t[2],c=0;if(o.some(function(e){return 0!==u[e]})){for(n in i)f.o(i,n)&&(f.m[n]=i[n]);a&&a(f)}for(e&&e(t);c<o.length;c++)r=o[c],f.o(u,r)&&u[r]&&u[r][0](),u[r]=0},(l=self.webpackChunk_nocobase_plugin_api_keys_client_v2=self.webpackChunk_nocobase_plugin_api_keys_client_v2||[]).forEach(c.bind(null,0)),l.push=c.bind(null,l.push.bind(l));var g={};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 n=window.__webpack_public_path__||"";n&&("/"!==n.charAt(n.length-1)&&(n+="/"),e=n+"static/plugins/@nocobase/plugin-api-keys/dist/client-v2/")}if(!e){if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var r=window.location.pathname||"/",o=r.indexOf("/v2/");e=o>=0?r.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-v2/"}f.p=e}(),!function(){f.r(g),f.d(g,{default:function(){return u}});var e=f(485);function t(e,t,n,r,o,i,a){try{var u=e[i](a),c=u.value}catch(e){n(e);return}u.done?t(c):Promise.resolve(c).then(r,o)}function n(e,t,r){return(n=a()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&o(i,n.prototype),i}).apply(null,arguments)}function r(e){return(r=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 n(e,arguments,r(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),o(i,e)})(e)}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(a=function(){return!!e})()}var u=function(e){var n;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=r(e),function(e,t){var n;if(t&&("object"==((n=t)&&"u">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||[],r(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),n=[{key:"load",value:function(){var e;return(e=function(){var e;return function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(a,"next",{value:c(0)}),u(a,"throw",{value:c(1)}),u(a,"return",{value:c(2)}),"function"==typeof Symbol&&u(a,Symbol.iterator,{value:function(){return this}}),a;function c(u){return function(c){var l=[u,c];if(n)throw TypeError("Generator is already executing.");for(;a&&(a=0,l[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=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++,r=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],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}(this,function(t){return e=this.t("API keys"),this.pluginSettingsManager.addMenuItem({key:"api-keys",title:e,icon:"KeyOutlined",aclSnippet:"pm.api-keys.configuration"}),this.pluginSettingsManager.addPageTabItem({menuKey:"api-keys",key:"index",title:e,componentLoader:function(){return f.e("849").then(f.bind(f,648))}}),[2]})},function(){var n=this,r=arguments;return new Promise(function(o,i){var a=e.apply(n,r);function u(e){t(a,o,i,u,c,"next",e)}function c(e){t(a,o,i,u,c,"throw",e)}u(void 0)})}).call(this)}}],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)}}(i.prototype,n),i}(i(e.Plugin))}(),g}()});
|
|
@@ -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
|
+
export declare function useT(): (key: string, options?: Record<string, any>) => string;
|
|
10
|
+
export declare function tExpr(key: string): string;
|
|
@@ -0,0 +1,59 @@
|
|
|
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 React from 'react';
|
|
10
|
+
type Role = {
|
|
11
|
+
name: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
};
|
|
14
|
+
export type ApiKeyFormValues = {
|
|
15
|
+
name: string;
|
|
16
|
+
role?: Role;
|
|
17
|
+
expiresIn: string;
|
|
18
|
+
};
|
|
19
|
+
export type ApiKeyRecord = {
|
|
20
|
+
id: number;
|
|
21
|
+
name: string;
|
|
22
|
+
role?: Role;
|
|
23
|
+
roleName?: string;
|
|
24
|
+
expiresIn: string;
|
|
25
|
+
createdAt?: string;
|
|
26
|
+
};
|
|
27
|
+
type CreateResponse = {
|
|
28
|
+
data?: {
|
|
29
|
+
data?: {
|
|
30
|
+
token?: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export type ApiKeyResource = {
|
|
35
|
+
create: (params: {
|
|
36
|
+
values: ApiKeyFormValues;
|
|
37
|
+
}) => Promise<CreateResponse>;
|
|
38
|
+
destroy: (params: {
|
|
39
|
+
filterByTk: number | number[];
|
|
40
|
+
}) => Promise<unknown>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Pure submit pipeline so tests can pin the resource call shape (create →
|
|
44
|
+
* extract token → onCreated) and a future refactor cannot silently skip the
|
|
45
|
+
* POST while still closing the drawer. Mirrors the prevention rule documented
|
|
46
|
+
* in references/settings-page-crud.md (`No silent fallthrough on submit branches`).
|
|
47
|
+
*/
|
|
48
|
+
export declare function submitApiKeyForm(args: {
|
|
49
|
+
values: ApiKeyFormValues;
|
|
50
|
+
resource: ApiKeyResource;
|
|
51
|
+
onCreated: (token: string | undefined) => void;
|
|
52
|
+
}): Promise<void>;
|
|
53
|
+
export declare function deleteApiKey(args: {
|
|
54
|
+
resource: ApiKeyResource;
|
|
55
|
+
filterByTk: number;
|
|
56
|
+
onDeleted: () => void;
|
|
57
|
+
}): Promise<void>;
|
|
58
|
+
declare const ApiKeysPage: React.FC;
|
|
59
|
+
export default ApiKeysPage;
|
|
@@ -0,0 +1,30 @@
|
|
|
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 dayjs from 'dayjs';
|
|
10
|
+
import React from 'react';
|
|
11
|
+
export type ExpiresOption = {
|
|
12
|
+
label: string;
|
|
13
|
+
value: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Convert a future `dayjs` date into the `Xd` shape persisted by the apiKeys
|
|
17
|
+
* collection. Mirrors the v1 ExpiresSelect: zero out seconds/milliseconds on
|
|
18
|
+
* both ends and report the day difference.
|
|
19
|
+
*/
|
|
20
|
+
export declare function diffToExpiresIn(target: dayjs.Dayjs, now?: dayjs.Dayjs): string;
|
|
21
|
+
export declare function formatExpiresReadOnly(record: {
|
|
22
|
+
expiresIn?: string;
|
|
23
|
+
createdAt?: string;
|
|
24
|
+
}, neverLabel: string): string;
|
|
25
|
+
export declare function ExpiresEditor(props: {
|
|
26
|
+
value?: string;
|
|
27
|
+
onChange?: (next: string) => void;
|
|
28
|
+
options: ExpiresOption[];
|
|
29
|
+
}): React.JSX.Element;
|
|
30
|
+
export declare function useExpiresOptions(): ExpiresOption[];
|
|
@@ -0,0 +1,14 @@
|
|
|
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 type { Application } from '@nocobase/client-v2';
|
|
10
|
+
import { Plugin } from '@nocobase/client-v2';
|
|
11
|
+
export declare class PluginAPIKeysClientV2 extends Plugin<Record<string, never>, Application> {
|
|
12
|
+
load(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export default PluginAPIKeysClientV2;
|
package/dist/externalVersion.js
CHANGED
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "2.1.0-alpha.
|
|
12
|
-
"@nocobase/
|
|
13
|
-
"@nocobase/
|
|
11
|
+
"@nocobase/client": "2.1.0-alpha.40",
|
|
12
|
+
"@nocobase/flow-engine": "2.1.0-alpha.40",
|
|
13
|
+
"@nocobase/client-v2": "2.1.0-alpha.40",
|
|
14
|
+
"@nocobase/database": "2.1.0-alpha.40",
|
|
15
|
+
"@nocobase/server": "2.1.0-alpha.40",
|
|
14
16
|
"@formily/react": "2.3.7",
|
|
15
17
|
"ahooks": "3.7.8",
|
|
16
18
|
"antd": "5.24.2",
|
|
@@ -18,5 +20,6 @@ module.exports = {
|
|
|
18
20
|
"react": "18.2.0",
|
|
19
21
|
"@formily/shared": "2.3.7",
|
|
20
22
|
"react-i18next": "11.18.6",
|
|
21
|
-
"@
|
|
23
|
+
"@ant-design/icons": "5.6.1",
|
|
24
|
+
"@nocobase/actions": "2.1.0-alpha.40"
|
|
22
25
|
};
|
|
@@ -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
|
+
}
|
package/dist/server/plugin.d.ts
CHANGED
package/dist/server/plugin.js
CHANGED
|
@@ -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-alpha.
|
|
10
|
-
"license": "
|
|
9
|
+
"version": "2.1.0-alpha.40",
|
|
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",
|
|
@@ -29,11 +29,13 @@
|
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@nocobase/actions": "2.x",
|
|
31
31
|
"@nocobase/client": "2.x",
|
|
32
|
+
"@nocobase/client-v2": "2.x",
|
|
32
33
|
"@nocobase/database": "2.x",
|
|
34
|
+
"@nocobase/flow-engine": "2.x",
|
|
33
35
|
"@nocobase/resourcer": "2.x",
|
|
34
36
|
"@nocobase/server": "2.x",
|
|
35
37
|
"@nocobase/test": "2.x",
|
|
36
38
|
"@nocobase/utils": "2.x"
|
|
37
39
|
},
|
|
38
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "e73f99dd0abefe847f2e50ff0fea1f41a82fd048"
|
|
39
41
|
}
|
|
@@ -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}))}}}]);
|