@nocobase/plugin-api-keys 0.20.0-alpha.9 → 0.21.0-alpha.2
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/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +2 -2
- package/dist/client/locale/index.d.ts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/externalVersion.js +4 -4
- package/dist/server/plugin.d.ts +2 -5
- package/dist/server/plugin.js +26 -22
- package/package.json +2 -2
package/dist/client/index.d.ts
CHANGED
package/dist/client/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(t
|
|
1
|
+
(function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(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"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e["@nocobase/plugin-api-keys"]={},e["@nocobase/client"],e.jsxRuntime,e["@formily/react"],e.ahooks,e.antd,e.dayjs,e.react,e["react-i18next"],e["@formily/shared"]))})(this,function(e,t,o,p,x,s,d,m,i,y){"use strict";var Y=Object.defineProperty,H=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var D=(e,t,o)=>t in e?Y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,w=(e,t)=>{for(var o in t||(t={}))$.call(t,o)&&D(e,o,t[o]);if(P)for(var o of P(t))L.call(t,o)&&D(e,o,t[o]);return e},I=(e,t)=>H(e,W(t));var C=(e,t,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(e,t)).next())});const b="@nocobase/plugin-api-keys";function v(){return i.useTranslation([b,"client"],{nsMode:"fallback"})}const M=d().add(1,"days"),q=t.css`
|
|
2
2
|
width: 100%;
|
|
3
3
|
& > .ant-space-item {
|
|
4
4
|
flex: 1;
|
|
5
5
|
}
|
|
6
|
-
`,
|
|
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,2 +1,2 @@
|
|
|
1
1
|
export declare function lang(key: string): string;
|
|
2
|
-
export declare function useTranslation(): import("react-i18next").UseTranslationResponse<("api-keys" | "client")[], undefined>;
|
|
2
|
+
export declare function useTranslation(): import("react-i18next").UseTranslationResponse<("@nocobase/plugin-api-keys" | "client")[], undefined>;
|
package/dist/constants.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const NAMESPACE = "api-keys";
|
|
1
|
+
export declare const NAMESPACE = "@nocobase/plugin-api-keys";
|
package/dist/constants.js
CHANGED
|
@@ -20,7 +20,7 @@ __export(constants_exports, {
|
|
|
20
20
|
NAMESPACE: () => NAMESPACE
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(constants_exports);
|
|
23
|
-
const NAMESPACE = "api-keys";
|
|
23
|
+
const NAMESPACE = "@nocobase/plugin-api-keys";
|
|
24
24
|
// Annotate the CommonJS export names for ESM import in node:
|
|
25
25
|
0 && (module.exports = {
|
|
26
26
|
NAMESPACE
|
package/dist/externalVersion.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
"@nocobase/client": "0.
|
|
3
|
-
"@nocobase/database": "0.
|
|
4
|
-
"@nocobase/server": "0.
|
|
2
|
+
"@nocobase/client": "0.21.0-alpha.2",
|
|
3
|
+
"@nocobase/database": "0.21.0-alpha.2",
|
|
4
|
+
"@nocobase/server": "0.21.0-alpha.2",
|
|
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.
|
|
12
|
+
"@nocobase/actions": "0.21.0-alpha.2"
|
|
13
13
|
};
|
package/dist/server/plugin.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { Plugin } from '@nocobase/server';
|
|
2
|
-
export
|
|
3
|
-
name?: string;
|
|
4
|
-
}
|
|
5
|
-
export default class ApiKeysPlugin extends Plugin<ApiKeysPluginConfig> {
|
|
2
|
+
export declare class PluginAPIKeysServer extends Plugin {
|
|
6
3
|
resourceName: string;
|
|
7
|
-
constructor(app: any, options: any);
|
|
8
4
|
beforeLoad(): Promise<void>;
|
|
9
5
|
load(): Promise<void>;
|
|
10
6
|
}
|
|
7
|
+
export default PluginAPIKeysServer;
|
package/dist/server/plugin.js
CHANGED
|
@@ -17,23 +17,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
var plugin_exports = {};
|
|
19
19
|
__export(plugin_exports, {
|
|
20
|
-
|
|
20
|
+
PluginAPIKeysServer: () => PluginAPIKeysServer,
|
|
21
|
+
default: () => plugin_default
|
|
21
22
|
});
|
|
22
23
|
module.exports = __toCommonJS(plugin_exports);
|
|
23
24
|
var import_server = require("@nocobase/server");
|
|
24
|
-
var import_path = require("path");
|
|
25
|
-
var import_constants = require("../constants");
|
|
26
25
|
var import_api_keys = require("./actions/api-keys");
|
|
27
|
-
|
|
28
|
-
class ApiKeysPlugin extends import_server.Plugin {
|
|
26
|
+
class PluginAPIKeysServer extends import_server.Plugin {
|
|
29
27
|
resourceName = "apiKeys";
|
|
30
|
-
constructor(app, options) {
|
|
31
|
-
super(app, options);
|
|
32
|
-
}
|
|
33
28
|
async beforeLoad() {
|
|
34
|
-
this.app.
|
|
35
|
-
this.app.i18n.addResources("en-US", import_constants.NAMESPACE, import_locale.enUS);
|
|
36
|
-
await this.app.resourcer.define({
|
|
29
|
+
this.app.resourcer.define({
|
|
37
30
|
name: this.resourceName,
|
|
38
31
|
actions: {
|
|
39
32
|
create: import_api_keys.create,
|
|
@@ -47,17 +40,28 @@ class ApiKeysPlugin extends import_server.Plugin {
|
|
|
47
40
|
});
|
|
48
41
|
}
|
|
49
42
|
async load() {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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"
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
});
|
|
60
|
+
);
|
|
62
61
|
}
|
|
63
62
|
}
|
|
63
|
+
var plugin_default = PluginAPIKeysServer;
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
PluginAPIKeysServer
|
|
67
|
+
});
|
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.
|
|
7
|
+
"version": "0.21.0-alpha.2",
|
|
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": "
|
|
35
|
+
"gitHead": "90628f2e2da846208fb2d7966ddb4e467d187ffb"
|
|
36
36
|
}
|