@nocobase/plugin-api-keys 0.10.1-alpha.1 → 0.11.1-alpha.1

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,3 +1,3 @@
1
1
  import React from 'react';
2
- declare const ExpiresSelect: React.ForwardRefExoticComponent<Pick<Partial<any>, string | number | symbol> & React.RefAttributes<unknown>>;
2
+ declare const ExpiresSelect: React.ForwardRefExoticComponent<Omit<Partial<any>, "ref"> & React.RefAttributes<unknown>>;
3
3
  export { ExpiresSelect };
@@ -25,6 +25,13 @@ function _client() {
25
25
  };
26
26
  return data;
27
27
  }
28
+ function _client2() {
29
+ const data = require("@nocobase/utils/client");
30
+ _client2 = function _client2() {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
28
35
  function _ahooks() {
29
36
  const data = require("ahooks");
30
37
  _ahooks = function _ahooks() {
@@ -39,13 +46,6 @@ function _antd() {
39
46
  };
40
47
  return data;
41
48
  }
42
- function _moment() {
43
- const data = _interopRequireDefault(require("moment"));
44
- _moment = function _moment() {
45
- return data;
46
- };
47
- return data;
48
- }
49
49
  function _react2() {
50
50
  const data = _interopRequireWildcard(require("react"));
51
51
  _react2 = function _react2() {
@@ -56,7 +56,6 @@ function _react2() {
56
56
  var _locale = require("../locale");
57
57
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
58
58
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
59
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
60
59
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
61
60
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
62
61
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -68,7 +67,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
68
67
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
69
68
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
70
69
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
71
- const TOMORROW = (0, _moment().default)().add(1, 'days');
70
+ const TOMORROW = (0, _client2().dayjs)().add(1, 'days');
72
71
  const spaceCSS = (0, _css().css)`
73
72
  width: 100%;
74
73
  & > .ant-space-item {
@@ -93,8 +92,8 @@ const InternalExpiresSelect = props => {
93
92
  }
94
93
  };
95
94
  const onDatePickerChange = v => {
96
- v = v.milliseconds(0).second(0);
97
- const NOW = (0, _moment().default)().milliseconds(0).seconds(0);
95
+ v = v.millisecond(0).second(0);
96
+ const NOW = (0, _client2().dayjs)().millisecond(0).second(0);
98
97
  const value = `${v.diff(NOW, 'd')}d`;
99
98
  onChange(value);
100
99
  };
@@ -104,8 +103,8 @@ const InternalExpiresSelect = props => {
104
103
  value: isCustom ? 'custom' : props.value,
105
104
  onChange: onSelectChange
106
105
  })), isCustom ? _react2().default.createElement(_antd().DatePicker, {
107
- disabledDate: time => {
108
- return time.isSameOrBefore();
106
+ disabledDate: date => {
107
+ return date.isSameOrBefore();
109
108
  },
110
109
  defaultValue: TOMORROW,
111
110
  onChange: onDatePickerChange,
@@ -121,7 +120,7 @@ const ReadPretty = () => {
121
120
  t = _useTranslation.t;
122
121
  const expiresDate = (0, _react2().useMemo)(() => {
123
122
  if (expiresIn === 'never') return t('Never expires');
124
- return (0, _moment().default)(createdAt).add((expiresIn === null || expiresIn === void 0 ? void 0 : expiresIn.replace('d', '')) || 0, 'days').format('YYYY-MM-DD HH:mm:ss');
123
+ return (0, _client2().dayjs)(createdAt).add((expiresIn === null || expiresIn === void 0 ? void 0 : expiresIn.replace('d', '')) || 0, 'days').format('YYYY-MM-DD HH:mm:ss');
125
124
  }, [createdAt, expiresIn]);
126
125
  return _react2().default.createElement(_antd().Typography.Text, null, expiresDate);
127
126
  };
@@ -1,3 +1,5 @@
1
- import React from 'react';
2
- declare const ApiKeysProvider: React.NamedExoticComponent<object>;
3
- export default ApiKeysProvider;
1
+ import { Plugin } from '@nocobase/client';
2
+ declare class APIKeysPlugin extends Plugin {
3
+ load(): Promise<void>;
4
+ }
5
+ export default APIKeysPlugin;
@@ -21,6 +21,8 @@ function _react() {
21
21
  var _Configuration = require("./Configuration");
22
22
  var _locale = require("./locale");
23
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
25
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
24
26
  const ApiKeysProvider = _react().default.memo(props => {
25
27
  const _useTranslation = (0, _locale.useTranslation)(),
26
28
  t = _useTranslation.t;
@@ -42,5 +44,13 @@ const ApiKeysProvider = _react().default.memo(props => {
42
44
  }, props.children));
43
45
  });
44
46
  ApiKeysProvider.displayName = 'ApiKeysProvider';
45
- var _default = ApiKeysProvider;
47
+ class APIKeysPlugin extends _client().Plugin {
48
+ load() {
49
+ var _this = this;
50
+ return _asyncToGenerator(function* () {
51
+ _this.app.addProvider(ApiKeysProvider);
52
+ })();
53
+ }
54
+ }
55
+ var _default = APIKeysPlugin;
46
56
  exports.default = _default;
package/package.json CHANGED
@@ -4,21 +4,36 @@
4
4
  "displayName.zh-CN": "API keys",
5
5
  "description": "Allow users to use API key to access NocoBase's api",
6
6
  "description.zh-CN": "允许用户使用 API key 访问 NocoBase 的 api",
7
- "version": "0.10.1-alpha.1",
7
+ "version": "0.11.1-alpha.1",
8
8
  "license": "AGPL-3.0",
9
- "main": "./lib/index.js",
10
- "types": "./lib/index.d.ts",
11
- "dependencies": {
12
- "@nocobase/actions": "0.10.1-alpha.1",
13
- "@nocobase/database": "0.10.1-alpha.1",
14
- "@nocobase/resourcer": "0.10.1-alpha.1",
15
- "@nocobase/server": "0.10.1-alpha.1",
16
- "@nocobase/utils": "0.10.1-alpha.1",
17
- "jsonwebtoken": "^8.5.1"
18
- },
9
+ "main": "./lib/server/index.js",
10
+ "files": [
11
+ "lib",
12
+ "src",
13
+ "README.md",
14
+ "README.zh-CN.md",
15
+ "CHANGELOG.md",
16
+ "server.js",
17
+ "server.d.ts",
18
+ "client.js",
19
+ "client.d.ts"
20
+ ],
19
21
  "devDependencies": {
20
- "@nocobase/test": "0.10.1-alpha.1",
21
- "@types/jsonwebtoken": "^8.5.8"
22
+ "@formily/react": "2.2.26",
23
+ "@formily/shared": "2.2.26",
24
+ "@nocobase/actions": "0.11.1-alpha.1",
25
+ "@nocobase/client": "0.11.1-alpha.1",
26
+ "@nocobase/database": "0.11.1-alpha.1",
27
+ "@nocobase/resourcer": "0.11.1-alpha.1",
28
+ "@nocobase/server": "0.11.1-alpha.1",
29
+ "@nocobase/test": "0.11.1-alpha.1",
30
+ "@nocobase/utils": "0.11.1-alpha.1",
31
+ "antd": "^5.6.4",
32
+ "dayjs": "^1.11.8",
33
+ "i18next": "^22.4.9",
34
+ "react": "^18.2.0",
35
+ "react-dom": "^18.2.0",
36
+ "react-i18next": "^11.15.1"
22
37
  },
23
- "gitHead": "8f415f5e0ee2e72d681f9ab16af5911b52c374a9"
38
+ "gitHead": "9ed1dba520bc5f3a7cb1255ea8d92ccbefc11bc8"
24
39
  }
@@ -1,13 +1,13 @@
1
1
  import { css } from '@emotion/css';
2
2
  import { connect, mapProps, mapReadPretty } from '@formily/react';
3
3
  import { useRecord } from '@nocobase/client';
4
+ import { dayjs } from '@nocobase/utils/client';
4
5
  import { useBoolean } from 'ahooks';
5
6
  import { DatePicker, Select, Space, Typography } from 'antd';
6
- import moment from 'moment';
7
7
  import React, { useMemo } from 'react';
8
8
  import { useTranslation } from '../locale';
9
9
 
10
- const TOMORROW = moment().add(1, 'days');
10
+ const TOMORROW = dayjs().add(1, 'days');
11
11
 
12
12
  const spaceCSS = css`
13
13
  width: 100%;
@@ -30,9 +30,9 @@ const InternalExpiresSelect = (props) => {
30
30
  }
31
31
  };
32
32
 
33
- const onDatePickerChange = (v: moment.Moment) => {
34
- v = v.milliseconds(0).second(0);
35
- const NOW = moment().milliseconds(0).seconds(0);
33
+ const onDatePickerChange = (v: dayjs.Dayjs) => {
34
+ v = v.millisecond(0).second(0);
35
+ const NOW = dayjs().millisecond(0).second(0);
36
36
  const value = `${v.diff(NOW, 'd')}d`;
37
37
  onChange(value);
38
38
  };
@@ -42,8 +42,8 @@ const InternalExpiresSelect = (props) => {
42
42
  <Select {...props} value={isCustom ? 'custom' : props.value} onChange={onSelectChange}></Select>
43
43
  {isCustom ? (
44
44
  <DatePicker
45
- disabledDate={(time) => {
46
- return time.isSameOrBefore();
45
+ disabledDate={(date) => {
46
+ return date.isSameOrBefore();
47
47
  }}
48
48
  defaultValue={TOMORROW}
49
49
  onChange={onDatePickerChange}
@@ -61,7 +61,7 @@ const ReadPretty = () => {
61
61
  const expiresDate = useMemo(() => {
62
62
  if (expiresIn === 'never') return t('Never expires');
63
63
 
64
- return moment(createdAt)
64
+ return dayjs(createdAt)
65
65
  .add(expiresIn?.replace('d', '') || 0, 'days')
66
66
  .format('YYYY-MM-DD HH:mm:ss');
67
67
  }, [createdAt, expiresIn]);
@@ -1,4 +1,4 @@
1
- import { SchemaComponentOptions, SettingsCenterProvider } from '@nocobase/client';
1
+ import { Plugin, SchemaComponentOptions, SettingsCenterProvider } from '@nocobase/client';
2
2
  import React from 'react';
3
3
  import { Configuration } from './Configuration';
4
4
  import { useTranslation } from './locale';
@@ -26,4 +26,10 @@ const ApiKeysProvider = React.memo((props) => {
26
26
  });
27
27
  ApiKeysProvider.displayName = 'ApiKeysProvider';
28
28
 
29
- export default ApiKeysProvider;
29
+ class APIKeysPlugin extends Plugin {
30
+ async load() {
31
+ this.app.addProvider(ApiKeysProvider);
32
+ }
33
+ }
34
+
35
+ export default APIKeysPlugin;
@@ -1 +0,0 @@
1
- # API keys Changelog
@@ -1,9 +0,0 @@
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 `NocoBase` 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.
@@ -1,14 +0,0 @@
1
- [
2
- {
3
- "title": "Introduction",
4
- "path": "index"
5
- },
6
- {
7
- "title": "Usage",
8
- "path": "usage"
9
- },
10
- {
11
- "title": "Changelog",
12
- "path": "changelog"
13
- }
14
- ]
@@ -1,19 +0,0 @@
1
- # API keys Usage
2
-
3
- ## Creating an API key
4
-
5
- After enabling the plugin, go to the API keys plugin management page, click `Add API key`, fill in the relevant information, and click Save to create an API key.
6
-
7
- ## Using an API key
8
-
9
- Add the `Authorization` field to the request header, with the value of `Bearer ${API_KEY}`, to access all `NocoBase` APIs using the API key.
10
-
11
- Here's an example using cURL:
12
-
13
- ```bash
14
- curl '{domain}/api/roles:check' -H 'Authorization: Bearer {API key}'
15
- ```
16
-
17
- ## Deleting an API key
18
-
19
- After deleting the API key, it will no longer be usable.
@@ -1 +0,0 @@
1
- # API keys 更新日志
@@ -1,10 +0,0 @@
1
- # API keys
2
-
3
- ## 简介
4
-
5
- 该插件允许你创建和管理 API keys,生成的 API key 可以用于访问 `NocoBase` 所有 API。
6
-
7
-
8
- ## 权限控制
9
-
10
- 创建 API key 时,可以为该 Key 绑定角色,角色的权限就是 Key 的权限。
@@ -1,14 +0,0 @@
1
- [
2
- {
3
- "title": "介绍",
4
- "path": "index"
5
- },
6
- {
7
- "title": "用法",
8
- "path": "usage"
9
- },
10
- {
11
- "title": "日志",
12
- "path": "changelog"
13
- }
14
- ]
@@ -1,19 +0,0 @@
1
- # API keys 使用方法
2
-
3
- ## 创建 API key
4
-
5
- 当你启用插件后,前往 API keys 的插件管理页面,点击 `添加 API key` 并填写相关信息,点击 `保存` 即可创建 API key。
6
-
7
- ## 使用 API key
8
-
9
- 在请求头中添加 `Authorization` 字段,值为 `Bearer ${API_KEY}`,即可使用 API key 访问 `NocoBase` 所有 API。
10
-
11
- cURL 的例子如下
12
-
13
- ```bash
14
- curl '{domain}/api/roles:check' -H 'Authorization: Bearer {API key}'
15
- ```
16
-
17
- ## 删除 API key
18
-
19
- 删除 API key 后,该 Key 将无法继续使用。