Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vmm/service

Package Overview
Dependencies
Maintainers
9
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vmm/service - npm Package Compare versions

Comparing version 1.0.83 to 1.0.89

5

package.json
{
"name": "@vmm/service",
"version": "1.0.83",
"version": "1.0.89",
"main": "src/index.js",

@@ -23,4 +23,5 @@ "description": "VMM Service library",

"tsconfig-paths": "^3.9.0",
"tsconfig-paths-webpack-plugin": "^3.2.0"
"tsconfig-paths-webpack-plugin": "^3.2.0",
"typescript": "^4.9.4"
}
}

2

src/Argv.d.ts

@@ -13,3 +13,3 @@ export interface IArgDefines {

}
declare type IValue<T extends IArgDefines> = {
type IValue<T extends IArgDefines> = {
[P in keyof T]: T[P]["default"];

@@ -16,0 +16,0 @@ };

@@ -9,5 +9,8 @@ "use strict";

class Argv {
_appInfo;
_error;
_argDefines;
_args = {};
_parsedArgs = {};
constructor(argDefines, appInfo) {
this._args = {};
this._parsedArgs = {};
this._appInfo = appInfo;

@@ -14,0 +17,0 @@ this._argDefines = argDefines;

@@ -14,3 +14,3 @@ "use strict";

const logger_1 = require("./logger");
const log = logger_1.logger(`@vmm/service:Conf`);
const log = (0, logger_1.logger)(`@vmm/service:Conf`);
function loadConfigFile(fileName, configDefine) {

@@ -17,0 +17,0 @@ let configObject = {};

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.logger = exports.Mongo = exports.conf = exports.Argv = exports.SessionCrypto = exports.SESS_START = exports.Service = void 0;
const logger_1 = require("./logger");
const log = logger_1.logger(`@vmm/service:index`);
const log = (0, logger_1.logger)(`@vmm/service:index`);
log.info('vmm lib service start ...');

@@ -6,0 +7,0 @@ var Service_1 = require("./Service");

@@ -25,3 +25,3 @@ "use strict";

const m = methodName.substr(0, 1).toUpperCase();
return rawMethod.bind(_log, date_format_1.default('yyyyMMdd_hhmmss', new Date()), co(m + ':' + loggerName));
return rawMethod.bind(_log, (0, date_format_1.default)('yyyyMMdd_hhmmss', new Date()), co(m + ':' + loggerName));
};

@@ -28,0 +28,0 @@ if (process_1.default.env['DEBUG']) {

@@ -12,3 +12,3 @@ import { MongoClient, MongoClientOptions, Collection, ObjectId } from 'mongodb';

}
export declare type IExportCollections<T extends IDbSchemas> = {
export type IExportCollections<T extends IDbSchemas> = {
[K in keyof T]: Collection<T[K]['docSchema'] & {

@@ -15,0 +15,0 @@ _id: ObjectId;

@@ -10,8 +10,12 @@ "use strict";

const logger_1 = require("./logger");
const log = logger_1.logger(`@vmm/service:MongoDb`);
const log = (0, logger_1.logger)(`@vmm/service:MongoDb`);
class Mongo {
_url;
_options;
_modName;
_client = null;
_db = null;
_collections = {};
_dbCollectionsDefine;
constructor(url, options, modName, dbCollectionsDefine) {
this._client = null;
this._db = null;
this._collections = {};
log.debug('using db defines:', Object.keys(dbCollectionsDefine));

@@ -18,0 +22,0 @@ this._dbCollectionsDefine = dbCollectionsDefine;

@@ -11,3 +11,3 @@ "use strict";

const mongodb_1 = require("mongodb");
const log = logger_1.logger(`@vmm/service:restDbApi`);
const log = (0, logger_1.logger)(`@vmm/service:restDbApi`);
function _mergeExcludeFields(reqOptions, excludeFields) {

@@ -69,3 +69,3 @@ let options = reqOptions || {};

findOne: async (req, sessions) => {
assert_1.default(req.filter, 'need filter');
(0, assert_1.default)(req.filter, 'need filter');
const db = mongo.collections()[collName];

@@ -79,3 +79,3 @@ log.debug('findOne:', collName, req, sessions, _restOptions);

find: async (req, sessions) => {
assert_1.default(req.filter, 'need filter');
(0, assert_1.default)(req.filter, 'need filter');
const db = mongo.collections()[collName];

@@ -90,3 +90,3 @@ log.debug('find:', collName, req, sessions, _restOptions);

countDocuments: async (req, sessions) => {
assert_1.default(req.filter, 'need filter');
(0, assert_1.default)(req.filter, 'need filter');
const db = mongo.collections()[collName];

@@ -99,3 +99,3 @@ log.debug('countDocuments:', collName, req, sessions, _restOptions);

estimatedDocumentCount: async (req, sessions) => {
assert_1.default(req.filter, 'need filter');
(0, assert_1.default)(req.filter, 'need filter');
const db = mongo.collections()[collName];

@@ -108,3 +108,3 @@ log.debug('estimatedDocumentCount:', collName, req, sessions, _restOptions);

geoHaystackSearch: async (req, sessions) => {
assert_1.default(req.filter, 'need filter');
(0, assert_1.default)(req.filter, 'need filter');
const db = mongo.collections()[collName];

@@ -117,3 +117,3 @@ log.debug('geoHaystackSearch:', collName, req, sessions, _restOptions);

distinct: async (req, sessions) => {
assert_1.default(req.query, 'need query');
(0, assert_1.default)(req.query, 'need query');
if (lodash_1.default.isArray(_restOptions.excludeFields)) {

@@ -134,3 +134,3 @@ const kArray = lodash_1.default.trim(req.key).split('.');

insertOne: async (req, sessions) => {
assert_1.default(req.doc, 'need doc');
(0, assert_1.default)(req.doc, 'need doc');
const db = mongo.collections()[collName];

@@ -142,3 +142,3 @@ log.debug('insertOne:', collName, req, sessions, _restOptions);

insertMany: async (req, sessions) => {
assert_1.default(req.docs, 'need docs');
(0, assert_1.default)(req.docs, 'need docs');
const db = mongo.collections()[collName];

@@ -150,4 +150,4 @@ log.debug('insertMany:', collName, req, sessions, _restOptions);

updateOne: async (req, sessions) => {
assert_1.default(req.filter, 'need filter');
assert_1.default(req.update, 'need update');
(0, assert_1.default)(req.filter, 'need filter');
(0, assert_1.default)(req.update, 'need update');
const db = mongo.collections()[collName];

@@ -168,4 +168,4 @@ log.debug('updateOne 11:', collName, req, sessions, _restOptions);

updateMany: async (req, sessions) => {
assert_1.default(req.filter, 'need filter');
assert_1.default(req.update, 'need update');
(0, assert_1.default)(req.filter, 'need filter');
(0, assert_1.default)(req.update, 'need update');
const db = mongo.collections()[collName];

@@ -186,4 +186,4 @@ log.debug('updateOne 11:', collName, req, sessions, _restOptions);

findOneAndUpdate: async (req, sessions) => {
assert_1.default(req.filter, 'need filter');
assert_1.default(req.update, 'need update');
(0, assert_1.default)(req.filter, 'need filter');
(0, assert_1.default)(req.update, 'need update');
const db = mongo.collections()[collName];

@@ -204,4 +204,4 @@ log.debug('updateOne 11:', collName, req, sessions, _restOptions);

findOneAndReplace: async (req, sessions) => {
assert_1.default(req.filter, 'need filter');
assert_1.default(req.replacement, 'need update');
(0, assert_1.default)(req.filter, 'need filter');
(0, assert_1.default)(req.replacement, 'need update');
const db = mongo.collections()[collName];

@@ -222,3 +222,3 @@ log.debug('updateOne 11:', collName, req, sessions, _restOptions);

deleteOne: async (req, sessions) => {
assert_1.default(req.filter, 'need filter');
(0, assert_1.default)(req.filter, 'need filter');
const db = mongo.collections()[collName];

@@ -233,3 +233,3 @@ log.debug('deleteOne:', collName, req, sessions, _restOptions);

deleteMany: async (req, sessions) => {
assert_1.default(req.filter, 'need filter');
(0, assert_1.default)(req.filter, 'need filter');
const db = mongo.collections()[collName];

@@ -244,3 +244,3 @@ log.debug('deleteOne:', collName, req, sessions, _restOptions);

findOneAndDelete: async (req, sessions) => {
assert_1.default(req.filter, 'need filter');
(0, assert_1.default)(req.filter, 'need filter');
const db = mongo.collections()[collName];

@@ -247,0 +247,0 @@ log.debug('deleteOne:', collName, req, sessions, _restOptions);

/// <reference types="node" />
import { Request, Response } from 'express';
import { Server } from 'http';

@@ -8,8 +7,10 @@ import { Mongo } from './MongoDb';

export declare const SESS_START = "-cs-";
declare type ARGS_TYPE<T> = T extends (arg: infer U) => any ? U : never;
declare type RETURN_TYPE<T> = T extends (...args: any[]) => infer R ? R : any;
declare type SESSION_UPDATE_FUNC = {
type Request = any;
type Response = any;
type ARGS_TYPE<T> = T extends (arg: infer U) => any ? U : never;
type RETURN_TYPE<T> = T extends (...args: any[]) => infer R ? R : any;
type SESSION_UPDATE_FUNC = {
(expireSeconds?: number): void;
};
declare type FULL_SESSIONS<T> = T & {
type FULL_SESSIONS<T> = T & {
[k in keyof T]: {

@@ -19,7 +20,7 @@ update: SESSION_UPDATE_FUNC;

};
declare type REMAP_API_FUNCS<API_T, SESSIONS_T> = {
type REMAP_API_FUNCS<API_T, SESSIONS_T> = {
[P in keyof API_T]: (req: ARGS_TYPE<API_T[P]>, sessions: FULL_SESSIONS<SESSIONS_T>, httpRequest: Request, httpResponse: Response) => RETURN_TYPE<API_T[P]>;
};
declare type ApiFunction_T = (...args: any) => any;
export declare type ISeviceSession = {
type ApiFunction_T = (...args: any) => any;
export type ISeviceSession = {
[k in string]: {};

@@ -26,0 +27,0 @@ };

@@ -10,3 +10,3 @@ "use strict";

const logger_1 = require("./logger");
const log = logger_1.logger(`@vmm/service:Service`);
const log = (0, logger_1.logger)(`@vmm/service:Service`);
const crypto_1 = __importDefault(require("crypto"));

@@ -21,4 +21,5 @@ const assert_1 = __importDefault(require("assert"));

class SessionCrypto {
_key;
constructor(key) {
assert_1.default(key.length > 0);
(0, assert_1.default)(key.length > 0);
let k = key;

@@ -44,3 +45,3 @@ while (k.length < 32) {

enc(data) {
assert_1.default(lodash_1.default.isPlainObject(data));
(0, assert_1.default)(lodash_1.default.isPlainObject(data));
const enc = crypto_1.default.createCipheriv('aes-256-cbc', this._key, this._key.slice(16));

@@ -56,5 +57,11 @@ const encBuf = Buffer.concat([

class Service {
expressApp = (0, express_1.default)();
router = express_1.default.Router();
_options;
_name;
_sessionCrypto;
_servicePath;
api;
httpServer;
constructor(options) {
this.expressApp = express_1.default();
this.router = express_1.default.Router();
if (lodash_1.default.isEmpty(options.projectConfig.sessKey)) {

@@ -87,2 +94,3 @@ options.projectConfig.sessKey = crypto_1.default.randomBytes(8).toString('hex');

log.debug('-- using customApi:', `/${lodash_1.default.kebabCase(k)}`);
console.log('=========', options.customApi[k]);
this.router.use(`/${lodash_1.default.kebabCase(k)}`, options.customApi[k]);

@@ -103,3 +111,3 @@ });

lodash_1.default.forEach(this._options.api.db, (restDb, apiName) => {
const dbApis = restDbApi_1.createDbApi(this._options.mongo, restDb);
const dbApis = (0, restDbApi_1.createDbApi)(this._options.mongo, restDb);
lodash_1.default.forEach(restDb, (dbMethod, methodName) => {

@@ -112,2 +120,4 @@ const apiPath = `/db/${lodash_1.default.kebabCase(apiName)}/${lodash_1.default.kebabCase(methodName)}`;

}
this.expressApp.use(body_parser_1.default.urlencoded({ extended: false }));
this.expressApp.use(body_parser_1.default.json());
this.expressApp.use(this._servicePath, this.router);

@@ -227,2 +237,3 @@ this.httpServer = http_1.default.createServer(this.expressApp);

}
console.log('----sessions', sessions);
const userActors = lodash_1.default.get(sessions, ['user', 'client', 'actor']);

@@ -246,3 +257,3 @@ if (lodash_1.default.isEmpty(userActors)) {

for (const name of preDefinedApi._sessions) {
assert_1.default(this._options.api.session[name], `session define of ${name} not existed`);
(0, assert_1.default)(this._options.api.session[name], `session define of ${name} not existed`);
if (!lodash_1.default.isPlainObject(sessions[name])) {

@@ -249,0 +260,0 @@ log.debug('set default sessions:', name);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc