@tachybase/plugin-api-keys 0.23.8
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/.turbo/turbo-build.log +14 -0
- package/LICENSE +201 -0
- package/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/client.d.ts +3 -0
- package/client.js +65 -0
- package/dist/client/Configuration/ExpiresSelect.d.ts +3 -0
- package/dist/client/Configuration/index.d.ts +2 -0
- package/dist/client/Configuration/roles.d.ts +3 -0
- package/dist/client/Configuration/schema.d.ts +2 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +6 -0
- package/dist/client/locale/index.d.ts +2 -0
- package/dist/collections/apiKeys.d.ts +3 -0
- package/dist/collections/apiKeys.js +120 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +27 -0
- package/dist/externalVersion.js +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +21 -0
- package/dist/locale/ko_KR.json +21 -0
- package/dist/locale/zh-CN.json +21 -0
- package/dist/locale.d.ts +1 -0
- package/dist/locale.js +30 -0
- package/dist/server/actions/api-keys.d.ts +3 -0
- package/dist/server/actions/api-keys.js +84 -0
- package/dist/server/collections/apiKeys.d.ts +2 -0
- package/dist/server/collections/apiKeys.js +34 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/dist/server/locale/en-US.d.ts +2 -0
- package/dist/server/locale/en-US.js +23 -0
- package/dist/server/locale/fr-FR.d.ts +2 -0
- package/dist/server/locale/fr-FR.js +23 -0
- package/dist/server/locale/index.d.ts +2 -0
- package/dist/server/locale/index.js +40 -0
- package/dist/server/locale/zh-CN.d.ts +4 -0
- package/dist/server/locale/zh-CN.js +25 -0
- package/dist/server/plugin.d.ts +7 -0
- package/dist/server/plugin.js +85 -0
- package/dist/swagger/index.d.ts +106 -0
- package/dist/swagger/index.js +130 -0
- package/docs/en-US/changelog.md +1 -0
- package/docs/en-US/index.md +9 -0
- package/docs/en-US/tabs.json +14 -0
- package/docs/en-US/usage.md +21 -0
- package/docs/zh-CN/changelog.md +1 -0
- package/docs/zh-CN/index.md +10 -0
- package/docs/zh-CN/tabs.json +14 -0
- package/docs/zh-CN/usage.md +21 -0
- package/package.json +34 -0
- package/server.d.ts +3 -0
- package/server.js +1 -0
package/dist/locale.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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 locale_exports = {};
|
|
19
|
+
__export(locale_exports, {
|
|
20
|
+
generateNTemplate: () => generateNTemplate
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(locale_exports);
|
|
23
|
+
var import_constants = require("./constants");
|
|
24
|
+
function generateNTemplate(key) {
|
|
25
|
+
return `{{t('${key}', { ns: '${import_constants.NAMESPACE}', nsMode: 'fallback' })}}`;
|
|
26
|
+
}
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
generateNTemplate
|
|
30
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var api_keys_exports = {};
|
|
29
|
+
__export(api_keys_exports, {
|
|
30
|
+
create: () => create,
|
|
31
|
+
destroy: () => destroy
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(api_keys_exports);
|
|
34
|
+
var import_crypto = require("crypto");
|
|
35
|
+
var import_actions = __toESM(require("@tachybase/actions"));
|
|
36
|
+
async function create(ctx, next) {
|
|
37
|
+
const { values } = ctx.action.params;
|
|
38
|
+
if (!values.role) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const repository = ctx.db.getRepository("users.roles", ctx.auth.user.id);
|
|
42
|
+
const role = await repository.findOne({
|
|
43
|
+
filter: {
|
|
44
|
+
name: values.role.name
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
if (!role) {
|
|
48
|
+
throw ctx.throw(400, ctx.t("Role not found"));
|
|
49
|
+
}
|
|
50
|
+
const hash = (0, import_crypto.createHash)("sha256");
|
|
51
|
+
const jwtToken = ctx.app.authManager.jwt.sign(
|
|
52
|
+
{ userId: ctx.auth.user.id, roleName: role.name },
|
|
53
|
+
{ expiresIn: values.expiresIn }
|
|
54
|
+
);
|
|
55
|
+
hash.update(jwtToken);
|
|
56
|
+
const token = hash.digest("hex");
|
|
57
|
+
ctx.action.mergeParams({
|
|
58
|
+
values: {
|
|
59
|
+
token: jwtToken,
|
|
60
|
+
accessToken: token
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return import_actions.default.create(ctx, async () => {
|
|
64
|
+
ctx.body = {
|
|
65
|
+
token
|
|
66
|
+
};
|
|
67
|
+
await next();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async function destroy(ctx, next) {
|
|
71
|
+
const repo = ctx.db.getRepository(ctx.action.resourceName);
|
|
72
|
+
const { filterByTk } = ctx.action.params;
|
|
73
|
+
const data = await repo.findById(filterByTk);
|
|
74
|
+
const token = data == null ? void 0 : data.get("token");
|
|
75
|
+
if (token) {
|
|
76
|
+
await ctx.app.authManager.jwt.block(token);
|
|
77
|
+
}
|
|
78
|
+
return import_actions.default.destroy(ctx, next);
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
create,
|
|
83
|
+
destroy
|
|
84
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var apiKeys_exports = {};
|
|
29
|
+
__export(apiKeys_exports, {
|
|
30
|
+
default: () => apiKeys_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(apiKeys_exports);
|
|
33
|
+
var import_apiKeys = __toESM(require("../../collections/apiKeys"));
|
|
34
|
+
var apiKeys_default = import_apiKeys.default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './plugin';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var server_exports = {};
|
|
29
|
+
__export(server_exports, {
|
|
30
|
+
default: () => import_plugin.default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(server_exports);
|
|
33
|
+
var import_plugin = __toESM(require("./plugin"));
|
|
@@ -0,0 +1,23 @@
|
|
|
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 en_US_exports = {};
|
|
19
|
+
__export(en_US_exports, {
|
|
20
|
+
default: () => en_US_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(en_US_exports);
|
|
23
|
+
var en_US_default = {};
|
|
@@ -0,0 +1,23 @@
|
|
|
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 fr_FR_exports = {};
|
|
19
|
+
__export(fr_FR_exports, {
|
|
20
|
+
default: () => fr_FR_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(fr_FR_exports);
|
|
23
|
+
var fr_FR_default = {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var locale_exports = {};
|
|
29
|
+
__export(locale_exports, {
|
|
30
|
+
enUS: () => import_en_US.default,
|
|
31
|
+
zhCN: () => import_zh_CN.default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(locale_exports);
|
|
34
|
+
var import_en_US = __toESM(require("./en-US"));
|
|
35
|
+
var import_zh_CN = __toESM(require("./zh-CN"));
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
enUS,
|
|
39
|
+
zhCN
|
|
40
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
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 zh_CN_exports = {};
|
|
19
|
+
__export(zh_CN_exports, {
|
|
20
|
+
default: () => zh_CN_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(zh_CN_exports);
|
|
23
|
+
var zh_CN_default = {
|
|
24
|
+
"Role not found": "\u89D2\u8272\u4E0D\u5B58\u5728"
|
|
25
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
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 plugin_exports = {};
|
|
19
|
+
__export(plugin_exports, {
|
|
20
|
+
PluginAPIKeysServer: () => PluginAPIKeysServer,
|
|
21
|
+
default: () => plugin_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
24
|
+
var import_server = require("@tachybase/server");
|
|
25
|
+
var import_api_keys = require("./actions/api-keys");
|
|
26
|
+
class PluginAPIKeysServer extends import_server.Plugin {
|
|
27
|
+
resourceName = "apiKeys";
|
|
28
|
+
async beforeLoad() {
|
|
29
|
+
this.app.resourcer.define({
|
|
30
|
+
name: this.resourceName,
|
|
31
|
+
actions: {
|
|
32
|
+
create: import_api_keys.create,
|
|
33
|
+
destroy: import_api_keys.destroy
|
|
34
|
+
},
|
|
35
|
+
only: ["list", "create", "destroy"]
|
|
36
|
+
});
|
|
37
|
+
this.app.acl.registerSnippet({
|
|
38
|
+
name: ["pm", this.name, "configuration"].join("."),
|
|
39
|
+
actions: ["apiKeys:list", "apiKeys:create", "apiKeys:destroy"]
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async load() {
|
|
43
|
+
const repo = this.db.getRepository("apiKeys");
|
|
44
|
+
this.app.resourcer.use(
|
|
45
|
+
async (ctx, next) => {
|
|
46
|
+
const token = ctx.getBearerToken();
|
|
47
|
+
if ((token == null ? void 0 : token.length) !== 64) {
|
|
48
|
+
return await next();
|
|
49
|
+
}
|
|
50
|
+
const key = await repo.findOne({
|
|
51
|
+
filter: {
|
|
52
|
+
accessToken: token
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
ctx.getBearerToken = () => {
|
|
56
|
+
if (key) {
|
|
57
|
+
return key.token;
|
|
58
|
+
}
|
|
59
|
+
return token;
|
|
60
|
+
};
|
|
61
|
+
await next();
|
|
62
|
+
},
|
|
63
|
+
{ tag: "api-access-token", before: "auth" }
|
|
64
|
+
);
|
|
65
|
+
this.app.resourcer.use(
|
|
66
|
+
async (ctx, next) => {
|
|
67
|
+
const { resourceName, actionName } = ctx.action;
|
|
68
|
+
if (resourceName === this.resourceName && ["list", "destroy"].includes(actionName)) {
|
|
69
|
+
ctx.action.mergeParams({
|
|
70
|
+
filter: {
|
|
71
|
+
createdById: ctx.auth.user.id
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
await next();
|
|
76
|
+
},
|
|
77
|
+
{ tag: "resourceNameListDestroyFilter" }
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
var plugin_default = PluginAPIKeysServer;
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
PluginAPIKeysServer
|
|
85
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
info: {
|
|
3
|
+
title: string;
|
|
4
|
+
};
|
|
5
|
+
tags: any[];
|
|
6
|
+
paths: {
|
|
7
|
+
'/apiKeys:create': {
|
|
8
|
+
post: {
|
|
9
|
+
description: string;
|
|
10
|
+
tags: string[];
|
|
11
|
+
requestBody: {
|
|
12
|
+
content: {
|
|
13
|
+
'application/json': {
|
|
14
|
+
schema: {
|
|
15
|
+
$ref: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
responses: {
|
|
21
|
+
200: {
|
|
22
|
+
description: string;
|
|
23
|
+
content: {
|
|
24
|
+
'application/json': {
|
|
25
|
+
schema: {
|
|
26
|
+
type: string;
|
|
27
|
+
properties: {
|
|
28
|
+
token: {
|
|
29
|
+
type: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
'/apiKeys:list': {
|
|
40
|
+
get: {
|
|
41
|
+
description: string;
|
|
42
|
+
tags: string[];
|
|
43
|
+
responses: {
|
|
44
|
+
200: {
|
|
45
|
+
description: string;
|
|
46
|
+
content: {
|
|
47
|
+
'application/json': {
|
|
48
|
+
schema: {
|
|
49
|
+
type: string;
|
|
50
|
+
items: {
|
|
51
|
+
$ref: string;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
'/apiKeys:destroy/{filterByTk}': {
|
|
61
|
+
delete: {
|
|
62
|
+
description: string;
|
|
63
|
+
tags: string[];
|
|
64
|
+
parameters: {
|
|
65
|
+
name: string;
|
|
66
|
+
description: string;
|
|
67
|
+
required: boolean;
|
|
68
|
+
in: string;
|
|
69
|
+
schema: {
|
|
70
|
+
type: string;
|
|
71
|
+
example: number;
|
|
72
|
+
};
|
|
73
|
+
}[];
|
|
74
|
+
responses: {
|
|
75
|
+
200: {
|
|
76
|
+
description: string;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
components: {
|
|
83
|
+
schemas: {
|
|
84
|
+
apiKeys: {
|
|
85
|
+
type: string;
|
|
86
|
+
properties: {
|
|
87
|
+
id: {
|
|
88
|
+
type: string;
|
|
89
|
+
};
|
|
90
|
+
name: {
|
|
91
|
+
type: string;
|
|
92
|
+
example: string;
|
|
93
|
+
};
|
|
94
|
+
role: {
|
|
95
|
+
type: string;
|
|
96
|
+
};
|
|
97
|
+
expiresIn: {
|
|
98
|
+
type: string;
|
|
99
|
+
enum: string[];
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
export default _default;
|
|
@@ -0,0 +1,130 @@
|
|
|
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 swagger_exports = {};
|
|
19
|
+
__export(swagger_exports, {
|
|
20
|
+
default: () => swagger_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(swagger_exports);
|
|
23
|
+
var swagger_default = {
|
|
24
|
+
info: {
|
|
25
|
+
title: "TachyBase API - API keys plugin"
|
|
26
|
+
},
|
|
27
|
+
tags: [],
|
|
28
|
+
paths: {
|
|
29
|
+
"/apiKeys:create": {
|
|
30
|
+
post: {
|
|
31
|
+
description: "Create api key",
|
|
32
|
+
tags: ["apiKeys"],
|
|
33
|
+
requestBody: {
|
|
34
|
+
content: {
|
|
35
|
+
"application/json": {
|
|
36
|
+
schema: {
|
|
37
|
+
$ref: "#/components/schemas/apiKeys"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
responses: {
|
|
43
|
+
200: {
|
|
44
|
+
description: "successful operation",
|
|
45
|
+
content: {
|
|
46
|
+
"application/json": {
|
|
47
|
+
schema: {
|
|
48
|
+
type: "object",
|
|
49
|
+
properties: {
|
|
50
|
+
token: {
|
|
51
|
+
type: "string"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"/apiKeys:list": {
|
|
62
|
+
get: {
|
|
63
|
+
description: "get api keys",
|
|
64
|
+
tags: ["apiKeys"],
|
|
65
|
+
responses: {
|
|
66
|
+
200: {
|
|
67
|
+
description: "successful operation",
|
|
68
|
+
content: {
|
|
69
|
+
"application/json": {
|
|
70
|
+
schema: {
|
|
71
|
+
type: "array",
|
|
72
|
+
items: {
|
|
73
|
+
$ref: "#/components/schemas/apiKeys"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"/apiKeys:destroy/{filterByTk}": {
|
|
83
|
+
delete: {
|
|
84
|
+
description: "Create api key",
|
|
85
|
+
tags: ["apiKeys"],
|
|
86
|
+
parameters: [
|
|
87
|
+
{
|
|
88
|
+
name: "filterByTk",
|
|
89
|
+
description: "primary key",
|
|
90
|
+
required: true,
|
|
91
|
+
in: "path",
|
|
92
|
+
schema: {
|
|
93
|
+
type: "integer",
|
|
94
|
+
example: 1
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
responses: {
|
|
99
|
+
200: {
|
|
100
|
+
description: "successful operation"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
components: {
|
|
107
|
+
schemas: {
|
|
108
|
+
apiKeys: {
|
|
109
|
+
type: "object",
|
|
110
|
+
properties: {
|
|
111
|
+
id: {
|
|
112
|
+
type: "integer"
|
|
113
|
+
},
|
|
114
|
+
name: {
|
|
115
|
+
type: "string",
|
|
116
|
+
example: "key-name"
|
|
117
|
+
},
|
|
118
|
+
role: {
|
|
119
|
+
type: "object"
|
|
120
|
+
// $ref: '#/components/schemas/roles'
|
|
121
|
+
},
|
|
122
|
+
expiresIn: {
|
|
123
|
+
type: "string",
|
|
124
|
+
enum: ["1d", "7d", "30d", "90d", "never"]
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# API keys Changelog
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# API keys
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
This plugin allows you to create and manage API keys. The generated API key can be used to access all `TachyBase` APIs.
|
|
6
|
+
|
|
7
|
+
## Access control
|
|
8
|
+
|
|
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.
|