@steedos/service-api 2.7.1 → 2.7.2-beta.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/index.js +28 -26
- package/package.json +6 -6
package/index.js
CHANGED
|
@@ -106,7 +106,7 @@ module.exports = {
|
|
|
106
106
|
ServiceObjectGraphql
|
|
107
107
|
],
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
projectStarted: false,
|
|
110
110
|
|
|
111
111
|
// More info about settings: https://moleculer.services/docs/0.14/moleculer-web.html
|
|
112
112
|
settings: {
|
|
@@ -120,7 +120,7 @@ module.exports = {
|
|
|
120
120
|
|
|
121
121
|
// Global Express middlewares. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Middlewares
|
|
122
122
|
use: [
|
|
123
|
-
function(req, res, next) {
|
|
123
|
+
function (req, res, next) {
|
|
124
124
|
// 如果service-object-grapqhl未结算完成,则提示服务未就绪,刷新重试
|
|
125
125
|
if (!this.projectStarted) {
|
|
126
126
|
const message = 'service is not ready, please refresh later.';
|
|
@@ -182,7 +182,7 @@ module.exports = {
|
|
|
182
182
|
// Set request headers to context meta
|
|
183
183
|
ctx.meta.userAgent = req.headers["user-agent"];
|
|
184
184
|
ctx.meta.clientIp = requestIp.getClientIp(req);
|
|
185
|
-
},
|
|
185
|
+
},
|
|
186
186
|
|
|
187
187
|
/**
|
|
188
188
|
* After call hook. You can modify the data.
|
|
@@ -224,7 +224,7 @@ module.exports = {
|
|
|
224
224
|
res.end(JSON.stringify({ error: err.message, detail: err }));
|
|
225
225
|
} catch (error) {
|
|
226
226
|
res.writeHead(500);
|
|
227
|
-
res.end(JSON.stringify({ error: err.message}));
|
|
227
|
+
res.end(JSON.stringify({ error: err.message }));
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
},
|
|
@@ -308,7 +308,7 @@ module.exports = {
|
|
|
308
308
|
|
|
309
309
|
let msg = err.message;
|
|
310
310
|
|
|
311
|
-
if(err.code === 422 && err.type === 'VALIDATION_ERROR'){
|
|
311
|
+
if (err.code === 422 && err.type === 'VALIDATION_ERROR') {
|
|
312
312
|
msg = err.data.map(item => item.message).join('');
|
|
313
313
|
}
|
|
314
314
|
|
|
@@ -356,8 +356,8 @@ module.exports = {
|
|
|
356
356
|
getObjectDataLoaderMapKey(objectName, referenceToField = '_id', spaceId) {
|
|
357
357
|
if (objectName) {
|
|
358
358
|
const key = `${spaceId}_object:${objectName}.${referenceToField}`;
|
|
359
|
-
if(!ObjectDataLoaderMapKeys[objectName]){
|
|
360
|
-
ObjectDataLoaderMapKeys[objectName] = []
|
|
359
|
+
if (!ObjectDataLoaderMapKeys[objectName]) {
|
|
360
|
+
ObjectDataLoaderMapKeys[objectName] = [];
|
|
361
361
|
}
|
|
362
362
|
ObjectDataLoaderMapKeys[objectName].push(key);
|
|
363
363
|
return key;
|
|
@@ -369,7 +369,7 @@ module.exports = {
|
|
|
369
369
|
|
|
370
370
|
async objectDataLoaderHandler(actionName, staticParams, rootParams, graphqlCtx) {
|
|
371
371
|
const rootKeys = Object.keys(rootParams);
|
|
372
|
-
const {root, args, context, resolveInfo} = graphqlCtx;
|
|
372
|
+
const { root, args, context, resolveInfo } = graphqlCtx;
|
|
373
373
|
const userSession = context.ctx.meta.user;
|
|
374
374
|
const spaceId = userSession.spaceId;
|
|
375
375
|
const dataLoaderMapKey = this.getObjectDataLoaderMapKey(
|
|
@@ -437,7 +437,7 @@ module.exports = {
|
|
|
437
437
|
* @returns {Promise}
|
|
438
438
|
*/
|
|
439
439
|
async authenticate(ctx, route, req, res, alias) {
|
|
440
|
-
if(alias.authentication === false){
|
|
440
|
+
if (alias.authentication === false) {
|
|
441
441
|
return null;
|
|
442
442
|
}
|
|
443
443
|
let user = await steedosAuth.auth(req, res);
|
|
@@ -457,8 +457,10 @@ module.exports = {
|
|
|
457
457
|
* @returns {Promise}
|
|
458
458
|
*/
|
|
459
459
|
async authorize(ctx, route, req, res, alias) {
|
|
460
|
-
|
|
461
|
-
|
|
460
|
+
ctx.meta.requestHeaders = req.headers;
|
|
461
|
+
|
|
462
|
+
if (alias.authorization === false) {
|
|
463
|
+
return;
|
|
462
464
|
}
|
|
463
465
|
// Get the authenticated user.
|
|
464
466
|
const user = ctx.meta.user;
|
|
@@ -491,9 +493,9 @@ module.exports = {
|
|
|
491
493
|
const rootKeys = Object.keys(rootParams);
|
|
492
494
|
return async (root, args, context, resolveInfo) => {
|
|
493
495
|
try {
|
|
494
|
-
if(useObjectDataLoader){
|
|
495
|
-
return await this.objectDataLoaderHandler(actionName, staticParams, rootParams, {root, args, context, resolveInfo});
|
|
496
|
-
}else if (useDataLoader) {
|
|
496
|
+
if (useObjectDataLoader) {
|
|
497
|
+
return await this.objectDataLoaderHandler(actionName, staticParams, rootParams, { root, args, context, resolveInfo });
|
|
498
|
+
} else if (useDataLoader) {
|
|
497
499
|
const userSession = context.ctx.meta.user;
|
|
498
500
|
const spaceId = userSession.spaceId;
|
|
499
501
|
const dataLoaderMapKey = this.getDataLoaderMapKey(
|
|
@@ -688,7 +690,7 @@ module.exports = {
|
|
|
688
690
|
|
|
689
691
|
|
|
690
692
|
for (const objectName in this.ObjectsUIResolvers) {
|
|
691
|
-
if(resolvers[objectName]){
|
|
693
|
+
if (resolvers[objectName]) {
|
|
692
694
|
resolvers[objectName]['_ui'] = this.ObjectsUIResolvers[objectName];
|
|
693
695
|
}
|
|
694
696
|
}
|
|
@@ -997,33 +999,33 @@ module.exports = {
|
|
|
997
999
|
this.objectDataLoaders = new Map();
|
|
998
1000
|
this.app = SteedosRouter.staticRouter();
|
|
999
1001
|
},
|
|
1000
|
-
events:{
|
|
1001
|
-
'@objectRecordEvent.*.*': function(ctx){
|
|
1002
|
+
events: {
|
|
1003
|
+
'@objectRecordEvent.*.*': function (ctx) {
|
|
1002
1004
|
const { objectApiName, isUpdate, isDelete, id, doc } = ctx.params;
|
|
1003
|
-
if(objectApiName && (isUpdate || isDelete)){
|
|
1005
|
+
if (objectApiName && (isUpdate || isDelete)) {
|
|
1004
1006
|
const keys = ObjectDataLoaderMapKeys[objectApiName] || [];
|
|
1005
1007
|
let dataLoaderKeys = [id];
|
|
1006
|
-
if(objectApiName === 'space_users'){
|
|
1008
|
+
if (objectApiName === 'space_users') {
|
|
1007
1009
|
dataLoaderKeys.push(doc.user)
|
|
1008
1010
|
}
|
|
1009
|
-
_.each(keys, (key)=>{
|
|
1011
|
+
_.each(keys, (key) => {
|
|
1010
1012
|
const loader = this.objectDataLoaders.get(key);
|
|
1011
|
-
if(loader){
|
|
1012
|
-
for(const dataLoaderKey of dataLoaderKeys){
|
|
1013
|
+
if (loader) {
|
|
1014
|
+
for (const dataLoaderKey of dataLoaderKeys) {
|
|
1013
1015
|
loader.clear(dataLoaderKey);
|
|
1014
1016
|
}
|
|
1015
1017
|
}
|
|
1016
1018
|
})
|
|
1017
1019
|
}
|
|
1018
1020
|
},
|
|
1019
|
-
'service-ui.started': function(){
|
|
1021
|
+
'service-ui.started': function () {
|
|
1020
1022
|
this.app.use("/", this.express());
|
|
1021
1023
|
},
|
|
1022
|
-
"$packages.changed": function(){
|
|
1024
|
+
"$packages.changed": function () {
|
|
1023
1025
|
if (!this.projectStarted) {
|
|
1024
1026
|
this.projectStarted = true
|
|
1025
1027
|
// 开发环境, 显示耗时
|
|
1026
|
-
if(process.env.NODE_ENV == 'development' && global.__startDate){
|
|
1028
|
+
if (process.env.NODE_ENV == 'development' && global.__startDate) {
|
|
1027
1029
|
console.log('耗时: ' + (new Date().getTime() - global.__startDate.getTime()) + ' ms');
|
|
1028
1030
|
}
|
|
1029
1031
|
console.log(`Project is running at ${process.env.ROOT_URL}`);
|
|
@@ -1037,7 +1039,7 @@ module.exports = {
|
|
|
1037
1039
|
console.error('auto open browser failed.');
|
|
1038
1040
|
}
|
|
1039
1041
|
}, 100)
|
|
1040
|
-
|
|
1042
|
+
|
|
1041
1043
|
}
|
|
1042
1044
|
}
|
|
1043
1045
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-api",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.2-beta.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@steedos/auth": "2.7.
|
|
8
|
-
"@steedos/router": "2.7.
|
|
9
|
-
"@steedos/service-object-graphql": "2.7.
|
|
10
|
-
"@steedos/service-ui": "2.7.
|
|
7
|
+
"@steedos/auth": "2.7.2-beta.2",
|
|
8
|
+
"@steedos/router": "2.7.2-beta.2",
|
|
9
|
+
"@steedos/service-object-graphql": "2.7.2-beta.2",
|
|
10
|
+
"@steedos/service-ui": "2.7.2-beta.2",
|
|
11
11
|
"graphql": "^15.8.0",
|
|
12
12
|
"graphql-iso-date": "^3.6.1",
|
|
13
13
|
"graphql-type-json": "^0.3.2",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "21b9e28b2e7b707496e18eb1300a8b8d5efd660e",
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/graphql-iso-date": "^3.4.0",
|
|
28
28
|
"@types/react-dev-utils": "^9.0.11"
|