@vmm/service
Advanced tools
Comparing version 1.0.48 to 1.0.49
{ | ||
"name": "@vmm/service", | ||
"version": "1.0.48", | ||
"version": "1.0.49", | ||
"main": "src/index.js", | ||
@@ -5,0 +5,0 @@ "description": "VMM Service library", |
/// <reference types="node" /> | ||
import { Request, Response } from 'express'; | ||
import { Server } from 'http'; | ||
import { IExportCollections, IDbSchemas, Mongo } from './MongoDb'; | ||
import { Mongo } from './MongoDb'; | ||
import { RequestHandler } from 'express'; | ||
@@ -25,2 +25,22 @@ import { IConfig } from './Conf.js'; | ||
}; | ||
interface IApiDefines { | ||
pkg: { | ||
name: string; | ||
version: string; | ||
}; | ||
api: { | ||
[k: string]: ApiFunction_T; | ||
}; | ||
db: { | ||
[k: string]: { | ||
[k: string]: ApiFunction_T; | ||
}; | ||
}; | ||
session: { | ||
[k: string]: { | ||
client: any; | ||
server: any; | ||
}; | ||
}; | ||
} | ||
export declare class SessionCrypto { | ||
@@ -36,24 +56,14 @@ private _key; | ||
} | ||
interface IServiceOptions<T_API, T_RESTDB, T_SESSION> { | ||
interface IServiceOptions<T_API extends IApiDefines, T_RESTDB, T_SESSION> { | ||
host?: string; | ||
port: number; | ||
api: T_API; | ||
db?: { | ||
mongo: Mongo<any>; | ||
restDbApi: T_RESTDB; | ||
}; | ||
mongo?: Mongo<any>; | ||
projectConfig: IConfig & { | ||
sessKey: string; | ||
}; | ||
session: { | ||
define: T_SESSION; | ||
expireSeconds: number; | ||
}; | ||
sessionExpire: number; | ||
apiMiddleWares?: RequestHandler[]; | ||
} | ||
export declare class Service<T_API extends { | ||
[k: string]: ApiFunction_T; | ||
} & { | ||
__pkg?: any; | ||
}, T_DB extends IExportCollections<IDbSchemas>, T_RESTDB extends { | ||
export declare class Service<T_API extends IApiDefines, T_RESTDB extends { | ||
[k: string]: { | ||
@@ -60,0 +70,0 @@ [k: string]: ApiFunction_T; |
@@ -66,5 +66,5 @@ "use strict"; | ||
} | ||
this._name = options.api.__pkg.name; | ||
this._name = options.api.pkg.name; | ||
this._options = options; | ||
this._servicePath = `/api/${lodash_1.default.kebabCase(this._name)}`; | ||
this._servicePath = `/api/${lodash_1.default.kebabCase(this._name).replace(/-api$/, '')}`; | ||
this.api = lodash_1.default.clone(options.api); | ||
@@ -87,6 +87,6 @@ log.debug('api using service path:', this._servicePath); | ||
}); | ||
if (this._options.db) { | ||
lodash_1.default.forEach(this._options.db.restDbApi, (restDb, apiName) => { | ||
if (this._options.api.db) { | ||
lodash_1.default.forEach(this._options.api.db, (restDb, apiName) => { | ||
log.debug('using rest db api:', apiName, Object.keys(restDb).join()); | ||
const dbApis = restDbApi_1.createDbApi(this._options.db.mongo, restDb); | ||
const dbApis = restDbApi_1.createDbApi(this._options.mongo, restDb); | ||
lodash_1.default.forEach(restDb, (dbMethod, methodName) => { | ||
@@ -139,3 +139,3 @@ const apiPath = `/db/${lodash_1.default.kebabCase(apiName)}/${lodash_1.default.kebabCase(methodName)}`; | ||
const s = jsonwebtoken_1.default.sign(sess, this._options.projectConfig.sessKey, { | ||
expiresIn: sess._expire > 0 ? sess._expire : this._options.session.expireSeconds, | ||
expiresIn: sess._expire > 0 ? sess._expire : this._options.sessionExpire, | ||
}); | ||
@@ -227,6 +227,6 @@ return s; | ||
for (const name of preDefinedApi._sessions) { | ||
assert_1.default(this._options.session.define[name], `session define of ${name} not existed`); | ||
assert_1.default(this._options.api.session[name], `session define of ${name} not existed`); | ||
if (!lodash_1.default.isPlainObject(sessions[name])) { | ||
log.debug('set default sessions:', name); | ||
sessions[name] = lodash_1.default.cloneDeep(this._options.session.define[name]); | ||
sessions[name] = lodash_1.default.cloneDeep(this._options.api.session[name]); | ||
} | ||
@@ -233,0 +233,0 @@ Object.defineProperty(sessions[name], 'update', { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44565
1119