@nocobase/plugin-api-keys 0.21.0-alpha.1 → 0.21.0-alpha.11

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.
@@ -3,4 +3,4 @@
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(),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:q,children:[o.jsx(s.Select,I(w({},n),{value:c?"custom":n.value,onChange:h})),c?o.jsx(s.DatePicker,{disabledDate:l=>l.isSameOrBefore(),defaultValue:M,onChange:A,showToday:!1,allowClear:!1}):null]})},K=()=>{const{expiresIn:n,createdAt:a}=t.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));function r(n){return`{{t('${n}', { ns: '${b}', nsMode: 'fallback' })}}`}const B={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:j}=s.Modal,O=()=>{const n=p.useForm(),{setVisible:a}=t.useActionContext(),{resource:c,service:u}=t.useBlockRequestContext(),{t:f}=v(),[h,A]=j();return{run(){return C(this,null,function*(){var g,S;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:(S=(g=k.data)==null?void 0:g.data)==null?void 0:S.token})]})}),u==null||u.refresh()})},element:A}},N=()=>{const n=t.useRecord(),{resource:a,service:c}=t.useBlockRequestContext();return{run(){return C(this,null,function*(){yield a.destroy({filterByTk:n.id}),c.refresh()})}}},R={type:"object",properties:{configuration:{type:"void","x-decorator":"TableBlockProvider","x-decorator-props":{collection:B,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":{icon:"PlusOutlined",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:O}}}}}}},"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=t.useCurrentRoles();return o.jsx(t.SchemaComponentOptions,{scope:{currentRoles:n},components:{ExpiresSelect:V},children:o.jsx(p.RecursionField,{schema:R})})};class T extends t.Plugin{load(){return C(this,null,function*(){this.pluginSettingsManager.add(b,{icon:"KeyOutlined",title:this.t("API keys"),Component:E,aclSnippet:"pm.api-keys.configuration"})})}}e.PluginAPIKeysClient=T,e.default=T,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
6
+ `,F=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:q,children:[o.jsx(s.Select,I(w({},n),{value:c?"custom":n.value,onChange:h})),c?o.jsx(s.DatePicker,{disabledDate:l=>l.isSameOrBefore(),defaultValue:M,onChange:A,showToday:!1,allowClear:!1}):null]})},K=()=>{const{expiresIn:n,createdAt:a}=t.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));function r(n){return`{{t('${n}', { ns: '${b}', nsMode: 'fallback' })}}`}const B={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:j}=s.Modal,O=()=>{const n=p.useForm(),{setVisible:a}=t.useActionContext(),{resource:c,service:u}=t.useBlockRequestContext(),{t:f}=v(),[h,A]=j();return{run(){return C(this,null,function*(){var g,S;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:(S=(g=k.data)==null?void 0:g.data)==null?void 0:S.token})]})}),u==null||u.refresh()})},element:A}},N=()=>{const n=t.useRecord(),{resource:a,service:c}=t.useBlockRequestContext();return{run(){return C(this,null,function*(){yield a.destroy({filterByTk:n.id}),c.refresh()})}}},R={type:"object",properties:{configuration:{type:"void","x-decorator":"TableBlockProvider","x-decorator-props":{collection:B,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":{icon:"PlusOutlined",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:O}}}}}}},"x-align":"right"}}},[y.uid()]:{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: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=t.useCurrentRoles();return o.jsx(t.SchemaComponentOptions,{scope:{currentRoles:n},components:{ExpiresSelect:V},children:o.jsx(p.RecursionField,{schema:R})})};class T extends t.Plugin{load(){return C(this,null,function*(){this.pluginSettingsManager.add(b,{icon:"KeyOutlined",title:this.t("API keys"),Component:E,aclSnippet:"pm.api-keys.configuration"})})}}e.PluginAPIKeysClient=T,e.default=T,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,7 +1,7 @@
1
1
  module.exports = {
2
- "@nocobase/client": "0.21.0-alpha.1",
3
- "@nocobase/database": "0.21.0-alpha.1",
4
- "@nocobase/server": "0.21.0-alpha.1",
2
+ "@nocobase/client": "0.21.0-alpha.11",
3
+ "@nocobase/database": "0.21.0-alpha.11",
4
+ "@nocobase/server": "0.21.0-alpha.11",
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.21.0-alpha.1"
12
+ "@nocobase/actions": "0.21.0-alpha.11"
13
13
  };
@@ -40,17 +40,24 @@ class PluginAPIKeysServer extends import_server.Plugin {
40
40
  });
41
41
  }
42
42
  async load() {
43
- this.app.resourcer.use(async (ctx, next) => {
44
- const { resourceName, actionName } = ctx.action;
45
- if (resourceName === this.resourceName && ["list", "destroy"].includes(actionName)) {
46
- ctx.action.mergeParams({
47
- filter: {
48
- createdById: ctx.auth.user.id
49
- }
50
- });
43
+ this.app.resourcer.use(
44
+ async (ctx, next) => {
45
+ const { resourceName, actionName } = ctx.action;
46
+ if (resourceName === this.resourceName && ["list", "destroy"].includes(actionName)) {
47
+ ctx.action.mergeParams({
48
+ filter: {
49
+ createdById: ctx.auth.user.id
50
+ }
51
+ });
52
+ }
53
+ await next();
54
+ },
55
+ {
56
+ group: "apiKeys",
57
+ before: "acl",
58
+ after: "auth"
51
59
  }
52
- await next();
53
- });
60
+ );
54
61
  }
55
62
  }
56
63
  var plugin_default = PluginAPIKeysServer;
package/package.json CHANGED
@@ -4,7 +4,7 @@
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.21.0-alpha.1",
7
+ "version": "0.21.0-alpha.11",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/api-keys",
@@ -32,5 +32,5 @@
32
32
  "@nocobase/test": "0.x",
33
33
  "@nocobase/utils": "0.x"
34
34
  },
35
- "gitHead": "afd2f3d1341b85ea9daa7b2667dd4ace1fafb7ff"
35
+ "gitHead": "69fe8a6d75864a3ba98c5a6d3ebfe43a585d4cd3"
36
36
  }