@nocobase/plugin-users 0.5.0-alpha.36 → 0.7.0-alpha.0
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/LICENSE +201 -21
- package/esm/actions/users.d.ts +11 -0
- package/esm/actions/users.js +165 -0
- package/esm/actions/users.js.map +1 -0
- package/esm/collections/roles-users.d.ts +3 -0
- package/esm/collections/roles-users.js +5 -0
- package/esm/collections/roles-users.js.map +1 -0
- package/esm/collections/users.d.ts +3 -0
- package/esm/collections/users.js +86 -0
- package/esm/collections/users.js.map +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -0
- package/esm/jwt-service.d.ts +12 -0
- package/esm/jwt-service.js +26 -0
- package/esm/jwt-service.js.map +1 -0
- package/esm/middlewares/check.d.ts +1 -0
- package/esm/middlewares/check.js +22 -0
- package/esm/middlewares/check.js.map +1 -0
- package/esm/middlewares/index.d.ts +2 -0
- package/esm/middlewares/index.js +3 -0
- package/esm/middlewares/index.js.map +1 -0
- package/esm/middlewares/parseToken.d.ts +6 -0
- package/esm/middlewares/parseToken.js +64 -0
- package/esm/middlewares/parseToken.js.map +1 -0
- package/esm/models/UserModel.d.ts +4 -0
- package/esm/models/UserModel.js +53 -0
- package/esm/models/UserModel.js.map +1 -0
- package/esm/server.d.ts +23 -0
- package/esm/server.js +133 -0
- package/esm/server.js.map +1 -0
- package/lib/actions/users.d.ts +1 -0
- package/lib/actions/users.js +145 -241
- package/lib/actions/users.js.map +1 -1
- package/lib/collections/roles-users.d.ts +3 -0
- package/lib/collections/roles-users.js +7 -0
- package/lib/collections/roles-users.js.map +1 -0
- package/lib/collections/users.d.ts +2 -2
- package/lib/collections/users.js +85 -112
- package/lib/collections/users.js.map +1 -1
- package/lib/index.js +5 -30
- package/lib/index.js.map +1 -1
- package/lib/jwt-service.d.ts +12 -0
- package/lib/jwt-service.js +33 -0
- package/lib/jwt-service.js.map +1 -0
- package/lib/middlewares/check.d.ts +1 -1
- package/lib/middlewares/check.js +22 -60
- package/lib/middlewares/check.js.map +1 -1
- package/lib/middlewares/index.d.ts +2 -2
- package/lib/middlewares/index.js +6 -41
- package/lib/middlewares/index.js.map +1 -1
- package/lib/middlewares/parseToken.d.ts +6 -1
- package/lib/middlewares/parseToken.js +62 -63
- package/lib/middlewares/parseToken.js.map +1 -1
- package/lib/models/UserModel.d.ts +4 -0
- package/lib/models/UserModel.js +57 -0
- package/lib/models/UserModel.js.map +1 -0
- package/lib/server.d.ts +23 -3
- package/lib/server.js +147 -159
- package/lib/server.js.map +1 -1
- package/package.json +17 -6
- package/tsconfig.build.json +9 -0
- package/lib/actions/users.d.ts.map +0 -1
- package/lib/collections/users.d.ts.map +0 -1
- package/lib/fields/CreatedBy.d.ts +0 -11
- package/lib/fields/CreatedBy.d.ts.map +0 -1
- package/lib/fields/CreatedBy.js +0 -66
- package/lib/fields/CreatedBy.js.map +0 -1
- package/lib/fields/UpdatedBy.d.ts +0 -16
- package/lib/fields/UpdatedBy.d.ts.map +0 -1
- package/lib/fields/UpdatedBy.js +0 -87
- package/lib/fields/UpdatedBy.js.map +0 -1
- package/lib/fields/index.d.ts +0 -2
- package/lib/fields/index.d.ts.map +0 -1
- package/lib/fields/index.js +0 -43
- package/lib/fields/index.js.map +0 -1
- package/lib/fields/utils.d.ts +0 -4
- package/lib/fields/utils.d.ts.map +0 -1
- package/lib/fields/utils.js +0 -51
- package/lib/fields/utils.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/middlewares/check.d.ts.map +0 -1
- package/lib/middlewares/index.d.ts.map +0 -1
- package/lib/middlewares/parseToken.d.ts.map +0 -1
- package/lib/server.d.ts.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["fields/UpdatedBy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG/E,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC;IACtE,IAAI,EAAE,WAAW,GAAG,WAAW,CAAC;CACjC;AAED,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,SAAS;IAC9C,MAAM,CAAC,oBAAoB,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,KAAA,EAAE,EAAE,OAAO,EAAE;;KAAA;IAMhE,MAAM,CAAC,oBAAoB,CACzB,IAAI,EAAE,SAAS,EACf,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE;;;;KAAA;gBAerB,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,EAAE,gBAAgB,EAAE,OAAO,EAAE,YAAY;IAsBlE,WAAW,IAAI,QAAQ;CAG/B","file":"UpdatedBy.d.ts","sourcesContent":["import { BelongsToOptions, BELONGSTO, FieldContext } from '@nocobase/database';\nimport { setUserValue } from './utils';\n\nexport interface UpdatedByOptions extends Omit<BelongsToOptions, 'type'> {\n type: 'updatedBy' | 'updatedby';\n}\n\nexport default class UpdatedBy extends BELONGSTO {\n static beforeBulkCreateHook(this: UpdatedBy, models, { context }) {\n models.forEach((model) => {\n setUserValue.call(this, model, { context });\n });\n }\n\n static beforeBulkUpdateHook(\n this: UpdatedBy,\n { attributes, fields, context },\n ) {\n if (!context) {\n return;\n }\n const { currentUser } = context.state;\n if (!currentUser) {\n return;\n }\n fields.push(this.options.foreignKey);\n attributes[this.options.foreignKey] = currentUser.get(\n this.options.targetKey,\n );\n }\n\n constructor({ type, ...options }: UpdatedByOptions, context: FieldContext) {\n super({ ...options, type: 'belongsTo' } as BelongsToOptions, context);\n // const Model = context.sourceTable.getModel();\n // // TODO(feature): 可考虑策略模式,以在需要时对外提供接口\n // Model.addHook('beforeCreate', setUserValue.bind(this));\n // Model.addHook('beforeBulkCreate', UpdatedBy.beforeBulkCreateHook.bind(this));\n // Model.addHook('beforeUpdate', setUserValue.bind(this));\n // Model.addHook('beforeBulkUpdate', UpdatedBy.beforeBulkUpdateHook.bind(this));\n const { sourceTable, database } = context;\n const name = sourceTable.getName();\n database.on(`${name}.beforeCreate`, setUserValue.bind(this));\n database.on(\n `${name}.beforeBulkCreate`,\n UpdatedBy.beforeBulkCreateHook.bind(this),\n );\n database.on(`${name}.beforeUpdate`, setUserValue.bind(this));\n database.on(\n `${name}.beforeBulkUpdate`,\n UpdatedBy.beforeBulkUpdateHook.bind(this),\n );\n }\n\n public getDataType(): Function {\n return BELONGSTO;\n }\n}\n"]}
|
package/lib/fields/UpdatedBy.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _react() {
|
|
4
|
-
const data = _interopRequireDefault(require("react"));
|
|
5
|
-
|
|
6
|
-
_react = function _react() {
|
|
7
|
-
return data;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
16
|
-
var t = {};
|
|
17
|
-
|
|
18
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
19
|
-
|
|
20
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
21
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
22
|
-
}
|
|
23
|
-
return t;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
Object.defineProperty(exports, "__esModule", {
|
|
27
|
-
value: true
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const database_1 = require("@nocobase/database");
|
|
31
|
-
|
|
32
|
-
const utils_1 = require("./utils");
|
|
33
|
-
|
|
34
|
-
class UpdatedBy extends database_1.BELONGSTO {
|
|
35
|
-
static beforeBulkCreateHook(models, {
|
|
36
|
-
context
|
|
37
|
-
}) {
|
|
38
|
-
models.forEach(model => {
|
|
39
|
-
utils_1.setUserValue.call(this, model, {
|
|
40
|
-
context
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static beforeBulkUpdateHook({
|
|
46
|
-
attributes,
|
|
47
|
-
fields,
|
|
48
|
-
context
|
|
49
|
-
}) {
|
|
50
|
-
if (!context) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const currentUser = context.state.currentUser;
|
|
55
|
-
|
|
56
|
-
if (!currentUser) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
fields.push(this.options.foreignKey);
|
|
61
|
-
attributes[this.options.foreignKey] = currentUser.get(this.options.targetKey);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
constructor(_a, context) {
|
|
65
|
-
var type = _a.type,
|
|
66
|
-
options = __rest(_a, ["type"]);
|
|
67
|
-
|
|
68
|
-
super(Object.assign(Object.assign({}, options), {
|
|
69
|
-
type: 'belongsTo'
|
|
70
|
-
}), context);
|
|
71
|
-
const sourceTable = context.sourceTable,
|
|
72
|
-
database = context.database;
|
|
73
|
-
const name = sourceTable.getName();
|
|
74
|
-
database.on(`${name}.beforeCreate`, utils_1.setUserValue.bind(this));
|
|
75
|
-
database.on(`${name}.beforeBulkCreate`, UpdatedBy.beforeBulkCreateHook.bind(this));
|
|
76
|
-
database.on(`${name}.beforeUpdate`, utils_1.setUserValue.bind(this));
|
|
77
|
-
database.on(`${name}.beforeBulkUpdate`, UpdatedBy.beforeBulkUpdateHook.bind(this));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
getDataType() {
|
|
81
|
-
return database_1.BELONGSTO;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
exports.default = UpdatedBy;
|
|
87
|
-
//# sourceMappingURL=UpdatedBy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["fields/UpdatedBy.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iDAA+E;AAC/E,mCAAuC;AAMvC,MAAqB,SAAU,SAAQ,oBAAS;IAC9C,MAAM,CAAC,oBAAoB,CAAkB,MAAM,EAAE,EAAE,OAAO,EAAE;QAC9D,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACvB,oBAAY,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,oBAAoB,CAEzB,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE;QAE/B,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO;SACR;QACD,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC;QACtC,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO;SACR;QACD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACrC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC,GAAG,CACnD,IAAI,CAAC,OAAO,CAAC,SAAS,CACvB,CAAC;IACJ,CAAC;IAED,YAAY,EAAsC,EAAE,OAAqB;YAA7D,EAAE,IAAI,OAAgC,EAA3B,OAAO,cAAlB,QAAoB,CAAF;QAC5B,KAAK,CAAC,gCAAK,OAAO,KAAE,IAAI,EAAE,WAAW,GAAsB,EAAE,OAAO,CAAC,CAAC;QAOtE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;QAC1C,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,EAAE,CAAC;QACnC,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,eAAe,EAAE,oBAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7D,QAAQ,CAAC,EAAE,CACT,GAAG,IAAI,mBAAmB,EAC1B,SAAS,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAC1C,CAAC;QACF,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,eAAe,EAAE,oBAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7D,QAAQ,CAAC,EAAE,CACT,GAAG,IAAI,mBAAmB,EAC1B,SAAS,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAC1C,CAAC;IACJ,CAAC;IAEM,WAAW;QAChB,OAAO,oBAAS,CAAC;IACnB,CAAC;CACF;AAjDD,4BAiDC","file":"UpdatedBy.js","sourcesContent":["import { BelongsToOptions, BELONGSTO, FieldContext } from '@nocobase/database';\nimport { setUserValue } from './utils';\n\nexport interface UpdatedByOptions extends Omit<BelongsToOptions, 'type'> {\n type: 'updatedBy' | 'updatedby';\n}\n\nexport default class UpdatedBy extends BELONGSTO {\n static beforeBulkCreateHook(this: UpdatedBy, models, { context }) {\n models.forEach((model) => {\n setUserValue.call(this, model, { context });\n });\n }\n\n static beforeBulkUpdateHook(\n this: UpdatedBy,\n { attributes, fields, context },\n ) {\n if (!context) {\n return;\n }\n const { currentUser } = context.state;\n if (!currentUser) {\n return;\n }\n fields.push(this.options.foreignKey);\n attributes[this.options.foreignKey] = currentUser.get(\n this.options.targetKey,\n );\n }\n\n constructor({ type, ...options }: UpdatedByOptions, context: FieldContext) {\n super({ ...options, type: 'belongsTo' } as BelongsToOptions, context);\n // const Model = context.sourceTable.getModel();\n // // TODO(feature): 可考虑策略模式,以在需要时对外提供接口\n // Model.addHook('beforeCreate', setUserValue.bind(this));\n // Model.addHook('beforeBulkCreate', UpdatedBy.beforeBulkCreateHook.bind(this));\n // Model.addHook('beforeUpdate', setUserValue.bind(this));\n // Model.addHook('beforeBulkUpdate', UpdatedBy.beforeBulkUpdateHook.bind(this));\n const { sourceTable, database } = context;\n const name = sourceTable.getName();\n database.on(`${name}.beforeCreate`, setUserValue.bind(this));\n database.on(\n `${name}.beforeBulkCreate`,\n UpdatedBy.beforeBulkCreateHook.bind(this),\n );\n database.on(`${name}.beforeUpdate`, setUserValue.bind(this));\n database.on(\n `${name}.beforeBulkUpdate`,\n UpdatedBy.beforeBulkUpdateHook.bind(this),\n );\n }\n\n public getDataType(): Function {\n return BELONGSTO;\n }\n}\n"]}
|
package/lib/fields/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["fields/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC","file":"index.d.ts","sourcesContent":["export { default as CreatedBy } from './CreatedBy';\nexport { default as UpdatedBy } from './UpdatedBy';\n"]}
|
package/lib/fields/index.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _react() {
|
|
4
|
-
const data = _interopRequireDefault(require("react"));
|
|
5
|
-
|
|
6
|
-
_react = function _react() {
|
|
7
|
-
return data;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
16
|
-
return mod && mod.__esModule ? mod : {
|
|
17
|
-
"default": mod
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
Object.defineProperty(exports, "__esModule", {
|
|
22
|
-
value: true
|
|
23
|
-
});
|
|
24
|
-
exports.UpdatedBy = exports.CreatedBy = void 0;
|
|
25
|
-
|
|
26
|
-
var CreatedBy_1 = require("./CreatedBy");
|
|
27
|
-
|
|
28
|
-
Object.defineProperty(exports, "CreatedBy", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
get: function get() {
|
|
31
|
-
return __importDefault(CreatedBy_1).default;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
var UpdatedBy_1 = require("./UpdatedBy");
|
|
36
|
-
|
|
37
|
-
Object.defineProperty(exports, "UpdatedBy", {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function get() {
|
|
40
|
-
return __importDefault(UpdatedBy_1).default;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
//# sourceMappingURL=index.js.map
|
package/lib/fields/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["fields/index.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAmD;AAA1C,uHAAA,OAAO,OAAa;AAC7B,yCAAmD;AAA1C,uHAAA,OAAO,OAAa","file":"index.js","sourcesContent":["export { default as CreatedBy } from './CreatedBy';\nexport { default as UpdatedBy } from './UpdatedBy';\n"]}
|
package/lib/fields/utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["fields/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC;AAEzC,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,EAAE,KAAK,KAAA,EAAE,EAAE,OAAO,EAAE;;CAAA,QAoB3E","file":"utils.d.ts","sourcesContent":["import { CreatedBy, UpdatedBy } from '.';\n\nexport function setUserValue(this: CreatedBy | UpdatedBy, model, { context }) {\n const { foreignKey } = this.options;\n // 已有外键数据(只在创建时生效)\n if (model.getDataValue(foreignKey)) {\n if (model.isNewRecord) {\n return;\n }\n const changed = model.changed();\n if (Array.isArray(changed) && changed.find((key) => key === foreignKey)) {\n return;\n }\n }\n if (!context) {\n return;\n }\n const { currentUser } = context.state;\n if (!currentUser) {\n return;\n }\n model.set(foreignKey, currentUser.get(this.options.targetKey));\n}\n"]}
|
package/lib/fields/utils.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _react() {
|
|
4
|
-
const data = _interopRequireDefault(require("react"));
|
|
5
|
-
|
|
6
|
-
_react = function _react() {
|
|
7
|
-
return data;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
Object.defineProperty(exports, "__esModule", {
|
|
16
|
-
value: true
|
|
17
|
-
});
|
|
18
|
-
exports.setUserValue = void 0;
|
|
19
|
-
|
|
20
|
-
function setUserValue(model, {
|
|
21
|
-
context
|
|
22
|
-
}) {
|
|
23
|
-
const foreignKey = this.options.foreignKey;
|
|
24
|
-
|
|
25
|
-
if (model.getDataValue(foreignKey)) {
|
|
26
|
-
if (model.isNewRecord) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const changed = model.changed();
|
|
31
|
-
|
|
32
|
-
if (Array.isArray(changed) && changed.find(key => key === foreignKey)) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!context) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const currentUser = context.state.currentUser;
|
|
42
|
-
|
|
43
|
-
if (!currentUser) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
model.set(foreignKey, currentUser.get(this.options.targetKey));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
exports.setUserValue = setUserValue;
|
|
51
|
-
//# sourceMappingURL=utils.js.map
|
package/lib/fields/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["fields/utils.ts"],"names":[],"mappings":";;;AAEA,SAAgB,YAAY,CAA8B,KAAK,EAAE,EAAE,OAAO,EAAE;IAC1E,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;IAEpC,IAAI,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE;QAClC,IAAI,KAAK,CAAC,WAAW,EAAE;YACrB,OAAO;SACR;QACD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;QAChC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,UAAU,CAAC,EAAE;YACvE,OAAO;SACR;KACF;IACD,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO;KACR;IACD,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC;IACtC,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO;KACR;IACD,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;AACjE,CAAC;AApBD,oCAoBC","file":"utils.js","sourcesContent":["import { CreatedBy, UpdatedBy } from '.';\n\nexport function setUserValue(this: CreatedBy | UpdatedBy, model, { context }) {\n const { foreignKey } = this.options;\n // 已有外键数据(只在创建时生效)\n if (model.getDataValue(foreignKey)) {\n if (model.isNewRecord) {\n return;\n }\n const changed = model.changed();\n if (Array.isArray(changed) && changed.find((key) => key === foreignKey)) {\n return;\n }\n }\n if (!context) {\n return;\n }\n const { currentUser } = context.state;\n if (!currentUser) {\n return;\n }\n model.set(foreignKey, currentUser.get(this.options.targetKey));\n}\n"]}
|
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC","file":"index.d.ts","sourcesContent":["export { default } from './server';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["middlewares/check.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,OAAO,WAAW,OAAO,KAAA,yCAS/B","file":"check.d.ts","sourcesContent":["// TODO(usage): 拦截用户的处理暂时作为一个中间件导出,应用需要的时候可以直接使用这个中间件\nexport default function (options) {\n return async (ctx, next) => {\n const { currentUser } = ctx.state;\n if (!currentUser) {\n return ctx.throw(401, 'Unauthorized');\n }\n\n return next();\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["middlewares/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC","file":"index.d.ts","sourcesContent":["export { default as parseToken } from './parseToken';\nexport { default as check } from './check';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["middlewares/parseToken.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,WAAW,OAAO,KAAA,yCAe/B","file":"parseToken.d.ts","sourcesContent":["// TODO(feature): 表名应在 options 中配置\n// 中间件默认只解决解析 token 和附加对应 user 的工作,不解决是否提前报 401 退出。\n// 因为是否提供匿名访问资源是应用决定的,不是使用插件就一定不能匿名访问。\nexport default function (options) {\n return async (ctx, next) => {\n const token = ctx.get('Authorization').replace(/^Bearer\\s+/gi, '');\n const User = ctx.db.getModel('users');\n const user = await User.findOne({\n where: {\n token,\n },\n });\n if (user) {\n ctx.state.currentUser = user;\n }\n\n return next();\n };\n}\n"]}
|
package/lib/server.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["server.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;;AAEjD,wBA+CmB","file":"server.d.ts","sourcesContent":["import path from 'path';\nimport { registerFields, Table } from '@nocobase/database';\nimport * as fields from './fields';\nimport * as usersActions from './actions/users';\nimport * as middlewares from './middlewares';\nimport { PluginOptions } from '@nocobase/server';\n\nexport default {\n name: 'users',\n async load() {\n const database = this.app.db;\n const resourcer = this.app.resourcer;\n\n registerFields(fields);\n\n this.app.on('db.init', async () => {\n const User = database.getModel('users');\n await User.create({\n nickname: 'Super Admin',\n email: process.env.ADMIN_EMAIL || 'admin@nocobase.com',\n password: process.env.ADMIN_PASSWORD || 'admin123',\n });\n });\n\n database.on('afterTableInit', (table: Table) => {\n let { createdBy, updatedBy } = table.getOptions();\n if (createdBy !== false) {\n table.addField({\n type: 'createdBy',\n name: typeof createdBy === 'string' ? createdBy : 'createdBy',\n target: 'users',\n state: 0,\n });\n }\n if (updatedBy !== false) {\n table.addField({\n type: 'updatedBy',\n name: typeof updatedBy === 'string' ? updatedBy : 'updatedBy',\n target: 'users',\n state: 0,\n });\n }\n });\n\n database.import({\n directory: path.resolve(__dirname, 'collections'),\n });\n\n for (const [key, action] of Object.entries(usersActions)) {\n resourcer.registerActionHandler(`users:${key}`, action);\n }\n\n resourcer.use(middlewares.parseToken({}));\n },\n} as PluginOptions;\n"]}
|