@tachybase/plugin-api-keys 1.3.10 → 1.3.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.
@@ -1,6 +1,6 @@
1
- (function(t,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@tachybase/client"),require("react/jsx-runtime"),require("@tachybase/schema"),require("react"),require("ahooks"),require("antd"),require("dayjs"),require("react-i18next")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","react/jsx-runtime","@tachybase/schema","react","ahooks","antd","dayjs","react-i18next"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t["@tachybase/plugin-api-keys"]={},t["@tachybase/client"],t.jsxRuntime,t["@tachybase/schema"],t.react,t.ahooks,t.antd,t.dayjs,t["react-i18next"]))})(this,function(t,e,o,i,y,h,a,u,c){"use strict";var E=Object.defineProperty,Y=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var P=(t,e,o)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,D=(t,e)=>{for(var o in e||(e={}))W.call(e,o)&&P(t,o,e[o]);if(S)for(var o of S(e))$.call(e,o)&&P(t,o,e[o]);return t},w=(t,e)=>Y(t,H(e));var b=(t,e,o)=>new Promise((i,y)=>{var h=c=>{try{u(o.next(c))}catch(d){y(d)}},a=c=>{try{u(o.throw(c))}catch(d){y(d)}},u=c=>c.done?i(c.value):Promise.resolve(c.value).then(h,a);u((o=o.apply(t,e)).next())});const d="api-keys";function k(){return c.useTranslation([d,"core"],{nsMode:"fallback"})}const I=u().add(1,"days"),M=e.css`
1
+ (function(t,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@tachybase/client"),require("react/jsx-runtime"),require("@tachybase/schema"),require("react"),require("ahooks"),require("antd"),require("dayjs"),require("react-i18next")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","react/jsx-runtime","@tachybase/schema","react","ahooks","antd","dayjs","react-i18next"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t["@tachybase/plugin-api-keys"]={},t["@tachybase/client"],t.jsxRuntime,t["@tachybase/schema"],t.react,t.ahooks,t.antd,t.dayjs,t["react-i18next"]))})(this,function(t,e,o,i,y,b,a,u,c){"use strict";var E=Object.defineProperty,Y=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var P=(t,e,o)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,D=(t,e)=>{for(var o in e||(e={}))W.call(e,o)&&P(t,o,e[o]);if(S)for(var o of S(e))$.call(e,o)&&P(t,o,e[o]);return t},w=(t,e)=>Y(t,H(e));var h=(t,e,o)=>new Promise((i,y)=>{var b=c=>{try{u(o.next(c))}catch(d){y(d)}},a=c=>{try{u(o.throw(c))}catch(d){y(d)}},u=c=>c.done?i(c.value):Promise.resolve(c.value).then(b,a);u((o=o.apply(t,e)).next())});const d="api-keys";function k(){return c.useTranslation([d,"core"],{nsMode:"fallback"})}const I=u().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:s}=n,[l,{toggle:m,setFalse:x}]=h.useBoolean(),C=p=>{if(p==="custom")return s("1d"),m();x(),s(p)},g=p=>{p=p.millisecond(0).second(0);const A=u().millisecond(0).second(0),f=`${p.diff(A,"d")}d`;s(f)};return o.jsxs(a.Space,{className:M,children:[o.jsx(a.Select,w(D({},n),{value:l?"custom":n.value,onChange:C})),l?o.jsx(a.DatePicker,{disabledDate:p=>p.isSameOrBefore(),defaultValue:I,onChange:g,showToday:!1,allowClear:!1}):null]})},K=()=>{const{expiresIn:n,createdAt:s}=e.useRecord(),{t:l}=k(),m=y.useMemo(()=>n==="never"?l("Never expires"):u(s).add((n==null?void 0:n.replace("d",""))||0,"days").format("YYYY-MM-DD HH:mm:ss"),[s,n]);return o.jsx(a.Typography.Text,{children:m})},V=i.connect(F,i.mapProps({dataSource:"options"}),i.mapReadPretty(K));function r(n){return`{{t('${n}', { ns: '${d}', nsMode: 'fallback' })}}`}const q={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:"text",hidden:!0},{name:"accessToken",type:"string",hidden:!0}]},{useModal:B}=a.Modal,j=()=>{const n=i.useForm(),{setVisible:s}=e.useActionContext(),{resource:l,service:m}=e.useBlockRequestContext(),{t:x}=k(),[C,g]=B();return{run(){return b(this,null,function*(){var f,T;yield n.submit();const A=yield l.create({values:n.values});C.success({title:x("API key created successfully"),onOk:()=>{n.reset(),s(!1)},content:o.jsxs(a.Space,{direction:"vertical",children:[o.jsx(a.Alert,{message:x("Make sure to copy your personal access key now as you will not be able to see this again."),type:"warning"}),o.jsx(a.Typography.Text,{copyable:!0,children:(T=(f=A.data)==null?void 0:f.data)==null?void 0:T.token})]})}),m==null||m.refresh()})},element:g}},O=()=>{const n=e.useRecord(),{resource:s,service:l}=e.useBlockRequestContext();return{run(){return b(this,null,function*(){yield s.destroy({filterByTk:n.id}),l.refresh()})}}},N={type:"object",properties:{configuration:{type:"void","x-decorator":"TableBlockProvider","x-decorator-props":{collection:q,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(--tb-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:j}}}}}}},"x-align":"right"}}},[i.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:O}}}}}}}}}}}},R=()=>{const n=e.useCurrentRoles();return o.jsx(e.SchemaComponentOptions,{scope:{currentRoles:n},components:{ExpiresSelect:V},children:o.jsx(i.RecursionField,{schema:N})})};class v extends e.Plugin{load(){return b(this,null,function*(){this.userSettingsManager.add(d,{icon:"KeyOutlined",title:this.t("API keys"),Component:R,aclSnippet:"pm.api-keys.configuration"})})}}t.PluginAPIKeysClient=v,t.default=v,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
6
+ `,F=n=>{const{onChange:s}=n,[l,{toggle:m,setFalse:x}]=b.useBoolean(),g=p=>{if(p==="custom")return s("1d"),m();x(),s(p)},C=p=>{p=p.millisecond(0).second(0);const A=u().millisecond(0).second(0),f=`${p.diff(A,"d")}d`;s(f)};return o.jsxs(a.Space,{className:M,children:[o.jsx(a.Select,w(D({},n),{value:l?"custom":n.value,onChange:g})),l?o.jsx(a.DatePicker,{disabledDate:p=>p.isSameOrBefore(),defaultValue:I,onChange:C,showToday:!1,allowClear:!1}):null]})},K=()=>{const{expiresIn:n,createdAt:s}=e.useRecord(),{t:l}=k(),m=y.useMemo(()=>n==="never"?l("Never expires"):u(s).add((n==null?void 0:n.replace("d",""))||0,"days").format("YYYY-MM-DD HH:mm:ss"),[s,n]);return o.jsx(a.Typography.Text,{children:m})},V=i.connect(F,i.mapProps({dataSource:"options"}),i.mapReadPretty(K));function r(n){return`{{t('${n}', { ns: '${d}', nsMode: 'fallback' })}}`}const q={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,length:512},{name:"accessToken",type:"string",hidden:!0}]},{useModal:B}=a.Modal,j=()=>{const n=i.useForm(),{setVisible:s}=e.useActionContext(),{resource:l,service:m}=e.useBlockRequestContext(),{t:x}=k(),[g,C]=B();return{run(){return h(this,null,function*(){var f,T;yield n.submit();const A=yield l.create({values:n.values});g.success({title:x("API key created successfully"),onOk:()=>{n.reset(),s(!1)},content:o.jsxs(a.Space,{direction:"vertical",children:[o.jsx(a.Alert,{message:x("Make sure to copy your personal access key now as you will not be able to see this again."),type:"warning"}),o.jsx(a.Typography.Text,{copyable:!0,children:(T=(f=A.data)==null?void 0:f.data)==null?void 0:T.token})]})}),m==null||m.refresh()})},element:C}},O=()=>{const n=e.useRecord(),{resource:s,service:l}=e.useBlockRequestContext();return{run(){return h(this,null,function*(){yield s.destroy({filterByTk:n.id}),l.refresh()})}}},N={type:"object",properties:{configuration:{type:"void","x-decorator":"TableBlockProvider","x-decorator-props":{collection:q,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(--tb-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:j}}}}}}},"x-align":"right"}}},[i.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:O}}}}}}}}}}}},R=()=>{const n=e.useCurrentRoles();return o.jsx(e.SchemaComponentOptions,{scope:{currentRoles:n},components:{ExpiresSelect:V},children:o.jsx(i.RecursionField,{schema:N})})};class v extends e.Plugin{load(){return h(this,null,function*(){this.userSettingsManager.add(d,{icon:"KeyOutlined",title:this.t("API keys"),Component:R,aclSnippet:"pm.api-keys.configuration"})})}}t.PluginAPIKeysClient=v,t.default=v,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -108,8 +108,9 @@ var apiKeys_default = {
108
108
  },
109
109
  {
110
110
  name: "token",
111
- type: "text",
112
- hidden: true
111
+ type: "string",
112
+ hidden: true,
113
+ length: 512
113
114
  },
114
115
  {
115
116
  name: "accessToken",
@@ -1,12 +1,12 @@
1
1
  module.exports = {
2
- "@tachybase/client": "1.3.10",
3
- "@tachybase/database": "1.3.10",
4
- "@tachybase/server": "1.3.10",
2
+ "@tachybase/client": "1.3.11",
3
+ "@tachybase/database": "1.3.11",
4
+ "@tachybase/server": "1.3.11",
5
5
  "react": "18.3.1",
6
- "@tachybase/schema": "1.3.10",
6
+ "@tachybase/schema": "1.3.11",
7
7
  "ahooks": "3.8.4",
8
8
  "antd": "5.22.5",
9
9
  "dayjs": "1.11.13",
10
10
  "react-i18next": "15.2.0",
11
- "@tachybase/actions": "1.3.10"
11
+ "@tachybase/actions": "1.3.11"
12
12
  };
@@ -0,0 +1,6 @@
1
+ import { Migration } from '@tachybase/server';
2
+ export default class extends Migration {
3
+ on: string;
4
+ appVersion: string;
5
+ up(): Promise<void>;
6
+ }
@@ -0,0 +1,44 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var change_token_exports = {};
19
+ __export(change_token_exports, {
20
+ default: () => change_token_default
21
+ });
22
+ module.exports = __toCommonJS(change_token_exports);
23
+ var import_database = require("@tachybase/database");
24
+ var import_server = require("@tachybase/server");
25
+ class change_token_default extends import_server.Migration {
26
+ constructor() {
27
+ super(...arguments);
28
+ this.on = "beforeLoad";
29
+ // 'beforeLoad' or 'afterLoad'
30
+ this.appVersion = "<1.3.11";
31
+ }
32
+ async up() {
33
+ const tables = await this.db.sequelize.getQueryInterface().showAllTables();
34
+ if (!tables.includes("apiKeys")) {
35
+ this.app.logger.info(`[migration skipped] table apiKeys does not exist`);
36
+ return;
37
+ }
38
+ const queryInterface = this.db.sequelize.getQueryInterface();
39
+ await queryInterface.changeColumn("apiKeys", "token", {
40
+ type: import_database.DataTypes.STRING(512)
41
+ });
42
+ this.app.logger.info("apiKeys token change string(512) success!");
43
+ }
44
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tachybase/plugin-api-keys",
3
3
  "displayName": "Auth: API keys",
4
- "version": "1.3.10",
4
+ "version": "1.3.11",
5
5
  "description": "Allows users to use API key to access application's HTTP API",
6
6
  "keywords": [
7
7
  "Authentication"
@@ -16,16 +16,16 @@
16
16
  "react": "^18.3.1",
17
17
  "react-dom": "^18.3.1",
18
18
  "react-i18next": "^15.2.0",
19
- "@tachybase/schema": "1.3.10"
19
+ "@tachybase/schema": "1.3.11"
20
20
  },
21
21
  "peerDependencies": {
22
- "@tachybase/actions": "1.3.10",
23
- "@tachybase/database": "1.3.10",
24
- "@tachybase/client": "1.3.10",
25
- "@tachybase/resourcer": "1.3.10",
26
- "@tachybase/server": "1.3.10",
27
- "@tachybase/test": "1.3.10",
28
- "@tachybase/utils": "1.3.10"
22
+ "@tachybase/actions": "1.3.11",
23
+ "@tachybase/client": "1.3.11",
24
+ "@tachybase/server": "1.3.11",
25
+ "@tachybase/test": "1.3.11",
26
+ "@tachybase/utils": "1.3.11",
27
+ "@tachybase/database": "1.3.11",
28
+ "@tachybase/resourcer": "1.3.11"
29
29
  },
30
30
  "description.zh-CN": "允许用户使用 API 密钥访问应用的 HTTP API",
31
31
  "displayName.zh-CN": "认证:API 密钥",