@nocobase/plugin-api-keys 0.19.0-alpha.9 → 0.20.0-alpha.10

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.
@@ -1,6 +1,6 @@
1
- (function(t,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("@formily/react"),require("ahooks"),require("antd"),require("dayjs"),require("react"),require("react-i18next"),require("@formily/shared")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","@formily/react","ahooks","antd","dayjs","react","react-i18next","@formily/shared"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t["@nocobase/plugin-api-keys"]={},t["@nocobase/client"],t.jsxRuntime,t["@formily/react"],t.ahooks,t.antd,t.dayjs,t.react,t["react-i18next"],t["@formily/shared"]))})(this,function(t,e,o,p,x,s,d,m,i,y){"use strict";var Y=Object.defineProperty,H=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var D=(t,e,o)=>e in t?Y(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,P=(t,e)=>{for(var o in e||(e={}))$.call(e,o)&&D(t,o,e[o]);if(S)for(var o of S(e))L.call(e,o)&&D(t,o,e[o]);return t},w=(t,e)=>H(t,W(e));var C=(t,e,o)=>new Promise((p,x)=>{var s=i=>{try{m(o.next(i))}catch(y){x(y)}},d=i=>{try{m(o.throw(i))}catch(y){x(y)}},m=i=>i.done?p(i.value):Promise.resolve(i.value).then(s,d);m((o=o.apply(t,e)).next())});const h="api-keys";function r(n){return`{{t('${n}', { ns: '${h}', nsMode: 'fallback' })}}`}const M={dumpRules:{group:"user"},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:r("Expires"),"x-component":"ExpiresSelect",enum:[{label:r("1 Day"),value:"1d"},{label:r("7 Days"),value:"7d"},{label:r("30 Days"),value:"30d"},{label:r("90 Days"),value:"90d"},{label:r("Custom"),value:"custom"},{label:r("Never"),value:"never"}]}},{name:"token",type:"string",hidden:!0}]};function v(){return i.useTranslation([h,"client"],{nsMode:"fallback"})}const I=d().add(1,"days"),q=e.css`
1
+ (function(t,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("@formily/react"),require("ahooks"),require("antd"),require("dayjs"),require("react"),require("react-i18next"),require("@formily/shared")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","@formily/react","ahooks","antd","dayjs","react","react-i18next","@formily/shared"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t["@nocobase/plugin-api-keys"]={},t["@nocobase/client"],t.jsxRuntime,t["@formily/react"],t.ahooks,t.antd,t.dayjs,t.react,t["react-i18next"],t["@formily/shared"]))})(this,function(t,e,o,p,x,s,d,m,i,y){"use strict";var Y=Object.defineProperty,H=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var D=(t,e,o)=>e in t?Y(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,w=(t,e)=>{for(var o in e||(e={}))$.call(e,o)&&D(t,o,e[o]);if(S)for(var o of S(e))L.call(e,o)&&D(t,o,e[o]);return t},P=(t,e)=>H(t,W(e));var C=(t,e,o)=>new Promise((p,x)=>{var s=i=>{try{m(o.next(i))}catch(y){x(y)}},d=i=>{try{m(o.throw(i))}catch(y){x(y)}},m=i=>i.done?p(i.value):Promise.resolve(i.value).then(s,d);m((o=o.apply(t,e)).next())});const b="api-keys";function v(){return i.useTranslation([b,"client"],{nsMode:"fallback"})}const I=d().add(1,"days"),M=e.css`
2
2
  width: 100%;
3
3
  & > .ant-space-item {
4
4
  flex: 1;
5
5
  }
6
- `,F=n=>{const{onChange:a}=n,[c,{toggle:u,setFalse:f}]=x.useBoolean(),b=l=>{if(l==="custom")return a("1d"),u();f(),a(l)},A=l=>{l=l.millisecond(0).second(0);const k=d().millisecond(0).second(0),g=`${l.diff(k,"d")}d`;a(g)};return o.jsxs(s.Space,{className:q,children:[o.jsx(s.Select,w(P({},n),{value:c?"custom":n.value,onChange:b})),c?o.jsx(s.DatePicker,{disabledDate:l=>l.isSameOrBefore(),defaultValue:I,onChange:A,showToday:!1,allowClear:!1}):null]})},K=()=>{const{expiresIn:n,createdAt:a}=e.useRecord(),{t:c}=v(),u=m.useMemo(()=>n==="never"?c("Never expires"):d(a).add((n==null?void 0:n.replace("d",""))||0,"days").format("YYYY-MM-DD HH:mm:ss"),[a,n]);return o.jsx(s.Typography.Text,{children:u})},V=p.connect(F,p.mapProps({dataSource:"options"}),p.mapReadPretty(K)),{useModal:B}=s.Modal,j=()=>{const n=p.useForm(),{setVisible:a}=e.useActionContext(),{resource:c,service:u}=e.useBlockRequestContext(),{t:f}=v(),[b,A]=B();return{run(){return C(this,null,function*(){var g,T;yield n.submit();const k=yield c.create({values:n.values});b.success({title:f("API key created successfully"),onOk:()=>{n.reset(),a(!1)},content:o.jsxs(s.Space,{direction:"vertical",children:[o.jsx(s.Alert,{message:f("Make sure to copy your personal access key now as you will not be able to see this again."),type:"warning"}),o.jsx(s.Typography.Text,{copyable:!0,children:(T=(g=k.data)==null?void 0:g.data)==null?void 0:T.token})]})}),u==null||u.refresh()})},element:A}},N=()=>{const n=e.useRecord(),{resource:a,service:c}=e.useBlockRequestContext();return{run(){return C(this,null,function*(){yield a.destroy({filterByTk:n.id}),c.refresh()})}}},O={type:"object",properties:{configuration:{type:"void","x-decorator":"TableBlockProvider","x-decorator-props":{collection:"apiKeys",resource:"apiKeys",action:"list",params:{pageSize:20,appends:["role"],sort:["-createdAt"]},rowKey:"name",showIndex:!0},"x-component":"CardItem",properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:"var(--nb-spacing)"}},properties:{create:{type:"void","x-action":"create",title:r("Add API key"),"x-component":"Action","x-component-props":{openMode:"drawer",type:"primary"},properties:{drawer:{type:"void",title:r("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:r("Key name"),required:!0,"x-component":"CollectionField","x-decorator":"FormItem"},role:{type:"string",title:r("Role"),required:!0,"x-decorator-props":{tooltip:r("Allow only your own roles to be selected")},"x-collection-field":"apiKeys.role","x-component":"CollectionField","x-decorator":"FormItem"},expiresIn:{type:"string",title:r("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:j}}}}}}},"x-align":"right"}}},[y.uid()]:{type:"array","x-component":"TableV2","x-component-props":{rowKey:"id",useProps:"{{ useTableBlockProps }}"},properties:{column1:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:r("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:r("Role"),properties:{role:{type:"object","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:r("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:r("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:r("Delete API key"),content:"{{t('Are you sure you want to delete it?')}}"},useAction:N}}}}}}}}}}}},E=()=>{const n=e.useCurrentRoles();return o.jsx(e.CollectionManagerProvider,{collections:[M],children:o.jsx(e.SchemaComponentOptions,{scope:{currentRoles:n},components:{ExpiresSelect:V},children:o.jsx(p.RecursionField,{schema:O})})})};class R extends e.Plugin{load(){return C(this,null,function*(){this.app.pluginSettingsManager.add(h,{icon:"KeyOutlined",title:'{{t("API keys", {"ns": "api-keys"})}}',Component:E,aclSnippet:"pm.api-keys.configuration"})})}}t.default=R,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
6
+ `,q=n=>{const{onChange:a}=n,[c,{toggle:u,setFalse:f}]=x.useBoolean(),h=l=>{if(l==="custom")return a("1d"),u();f(),a(l)},A=l=>{l=l.millisecond(0).second(0);const k=d().millisecond(0).second(0),g=`${l.diff(k,"d")}d`;a(g)};return o.jsxs(s.Space,{className:M,children:[o.jsx(s.Select,P(w({},n),{value:c?"custom":n.value,onChange:h})),c?o.jsx(s.DatePicker,{disabledDate:l=>l.isSameOrBefore(),defaultValue:I,onChange:A,showToday:!1,allowClear:!1}):null]})},F=()=>{const{expiresIn:n,createdAt:a}=e.useRecord(),{t:c}=v(),u=m.useMemo(()=>n==="never"?c("Never expires"):d(a).add((n==null?void 0:n.replace("d",""))||0,"days").format("YYYY-MM-DD HH:mm:ss"),[a,n]);return o.jsx(s.Typography.Text,{children:u})},V=p.connect(q,p.mapProps({dataSource:"options"}),p.mapReadPretty(F));function r(n){return`{{t('${n}', { ns: '${b}', nsMode: 'fallback' })}}`}const K={dumpRules:{group:"user"},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:r("Expires"),"x-component":"ExpiresSelect",enum:[{label:r("1 Day"),value:"1d"},{label:r("7 Days"),value:"7d"},{label:r("30 Days"),value:"30d"},{label:r("90 Days"),value:"90d"},{label:r("Custom"),value:"custom"},{label:r("Never"),value:"never"}]}},{name:"token",type:"string",hidden:!0}]},{useModal:B}=s.Modal,j=()=>{const n=p.useForm(),{setVisible:a}=e.useActionContext(),{resource:c,service:u}=e.useBlockRequestContext(),{t:f}=v(),[h,A]=B();return{run(){return C(this,null,function*(){var g,T;yield n.submit();const k=yield c.create({values:n.values});h.success({title:f("API key created successfully"),onOk:()=>{n.reset(),a(!1)},content:o.jsxs(s.Space,{direction:"vertical",children:[o.jsx(s.Alert,{message:f("Make sure to copy your personal access key now as you will not be able to see this again."),type:"warning"}),o.jsx(s.Typography.Text,{copyable:!0,children:(T=(g=k.data)==null?void 0:g.data)==null?void 0:T.token})]})}),u==null||u.refresh()})},element:A}},N=()=>{const n=e.useRecord(),{resource:a,service:c}=e.useBlockRequestContext();return{run(){return C(this,null,function*(){yield a.destroy({filterByTk:n.id}),c.refresh()})}}},O={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:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:"var(--nb-spacing)"}},properties:{create:{type:"void","x-action":"create",title:r("Add API key"),"x-component":"Action","x-component-props":{openMode:"drawer",type:"primary"},properties:{drawer:{type:"void",title:r("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:r("Key name"),required:!0,"x-component":"CollectionField","x-decorator":"FormItem"},role:{type:"string",title:r("Role"),required:!0,"x-decorator-props":{tooltip:r("Allow only your own roles to be selected")},"x-collection-field":"apiKeys.role","x-component":"CollectionField","x-decorator":"FormItem"},expiresIn:{type:"string",title:r("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:j}}}}}}},"x-align":"right"}}},[y.uid()]:{type:"array","x-component":"TableV2","x-component-props":{rowKey:"id",useProps:"{{ useTableBlockProps }}"},properties:{column1:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:r("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:r("Role"),properties:{role:{type:"object","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:r("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:r("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:r("Delete API key"),content:"{{t('Are you sure you want to delete it?')}}"},useAction:N}}}}}}}}}}}},R=()=>{const n=e.useCurrentRoles();return o.jsx(e.SchemaComponentOptions,{scope:{currentRoles:n},components:{ExpiresSelect:V},children:o.jsx(p.RecursionField,{schema:O})})};class E extends e.Plugin{load(){return C(this,null,function*(){this.app.pluginSettingsManager.add(b,{icon:"KeyOutlined",title:'{{t("API keys", {"ns": "api-keys"})}}',Component:R,aclSnippet:"pm.api-keys.configuration"})})}}t.default=E,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,7 +1,7 @@
1
1
  module.exports = {
2
- "@nocobase/client": "0.19.0-alpha.9",
3
- "@nocobase/database": "0.19.0-alpha.9",
4
- "@nocobase/server": "0.19.0-alpha.9",
2
+ "@nocobase/client": "0.20.0-alpha.10",
3
+ "@nocobase/database": "0.20.0-alpha.10",
4
+ "@nocobase/server": "0.20.0-alpha.10",
5
5
  "@formily/react": "2.3.0",
6
6
  "ahooks": "3.7.8",
7
7
  "antd": "5.12.8",
@@ -9,5 +9,5 @@ module.exports = {
9
9
  "react": "18.2.0",
10
10
  "@formily/shared": "2.3.0",
11
11
  "react-i18next": "11.18.6",
12
- "@nocobase/actions": "0.19.0-alpha.9"
12
+ "@nocobase/actions": "0.20.0-alpha.10"
13
13
  };
@@ -4,6 +4,6 @@
4
4
 
5
5
  This plugin allows you to create and manage API keys. The generated API key can be used to access all `NocoBase` APIs.
6
6
 
7
- ## Access Control
7
+ ## Access control
8
8
 
9
9
  When creating an API key, you can bind it to a role, and the role's permissions will be the same as the Key's permissions.
package/package.json CHANGED
@@ -4,11 +4,11 @@
4
4
  "displayName.zh-CN": "认证:API 密钥",
5
5
  "description": "Allows users to use API key to access application's HTTP API",
6
6
  "description.zh-CN": "允许用户使用 API 密钥访问应用的 HTTP API",
7
- "version": "0.19.0-alpha.9",
7
+ "version": "0.20.0-alpha.10",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
- "homepage": "https://docs.nocobase.com/plugins/api-keys",
11
- "homepage.zh-CN": "https://docs-cn.nocobase.com/plugins/api-keys",
10
+ "homepage": "https://docs.nocobase.com/handbook/api-keys",
11
+ "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/api-keys",
12
12
  "keywords": [
13
13
  "Authentication"
14
14
  ],
@@ -32,5 +32,5 @@
32
32
  "@nocobase/test": "0.x",
33
33
  "@nocobase/utils": "0.x"
34
34
  },
35
- "gitHead": "975f9c58a1995df6a8d7a4d191a0dc4a9769ebc5"
35
+ "gitHead": "453e0774dae21750e96c7ddd2019c8889a0314d6"
36
36
  }