blixify-server 0.1.6 → 0.1.8
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.
|
@@ -14,7 +14,8 @@ export declare class MongoWrapper {
|
|
|
14
14
|
config: SecurityConfig;
|
|
15
15
|
lib: WrapperLib;
|
|
16
16
|
modelChecker: (obj: any) => boolean;
|
|
17
|
-
|
|
17
|
+
tableId: string;
|
|
18
|
+
constructor(mongoDB: any, collection: string, isProd: boolean, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean, lib: WrapperLib, tableId?: string);
|
|
18
19
|
initCreate: (req: any, res: any) => Promise<void>;
|
|
19
20
|
initGet: (req: any, res: any) => Promise<void>;
|
|
20
21
|
initUpdate: (req: any, res: any) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAOA,OAAO,cAAc,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAOA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAEhB,YAAY,QAAS,GAAG,aAEtB;IACF,OAAO,SAAM;gBAGX,OAAO,EAAE,GAAG,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE,MAAM;IAYlB,UAAU,QAAe,GAAG,OAAO,GAAG,mBA6BpC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA8BjC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAiEpC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAkCpC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBAyGlC;IAEF,IAAI,YAuCF;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(t,r,d
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,a,r,d){return new(r=r||Promise)(function(i,e){function s(t){try{n(d.next(t))}catch(t){e(t)}}function o(t){try{n(d.throw(t))}catch(t){e(t)}}function n(t){var e;t.done?i(t.value):((e=t.value)instanceof r?e:new r(function(t){t(e)})).then(s,o)}n((d=d.apply(t,a||[])).next())})},__importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MongoWrapper=void 0;const moment_1=__importDefault(require("moment")),QueryModel_1=require("../model/QueryModel");class MongoWrapper{constructor(t,e,i,s,o,n,a){this.mongoDB="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=t=>!1,this.tableId="",this.initCreate=(i,s)=>__awaiter(this,void 0,void 0,function*(){try{var t,e;this.modelChecker(i.body.data)?(t=(0,QueryModel_1.checkBaseConfig)(this.config,i),e=(0,QueryModel_1.checkOpsConfig)(this.config,"create",i,i.body.data),t&&e?(i.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),yield this.mongoDB.db(this.tableId).collection(this.collection).insertOne(i.body.data),s.send({success:!0})):s.status(400).json({err:"Invalid Security Configuration"})):s.status(400).json({err:"Invalid Model Structure"})}catch(t){s.status(400).json({err:t})}}),this.initGet=(o,n)=>__awaiter(this,void 0,void 0,function*(){try{var t,e,i,s=o.body.id;s?(t=yield this.mongoDB.db(this.tableId).collection(this.collection).findOne({_id:s}),e=(0,QueryModel_1.checkBaseConfig)(this.config,o),i=(0,QueryModel_1.checkOpsConfig)(this.config,"read",o,t),e&&i?n.send({data:t}):n.status(400).json({err:"Invalid Security Configuration"})):n.status(400).json({err:"Invalid Fields"})}catch(t){n.status(400).json({err:t})}}),this.initUpdate=(d,c)=>__awaiter(this,void 0,void 0,function*(){try{var t,e,i,s,o,n,a=this.modelChecker(d.body.data)&&d.body.id,r=t=>(delete t._id,t.baseUpdatedAt=(0,moment_1.default)().toDate(),t);a?(t=(0,QueryModel_1.checkBaseConfig)(this.config,d),e=(0,QueryModel_1.checkOpsConfig)(this.config,"update",d,d.body.data),t&&e?(i=this.mongoDB.db(this.tableId).collection(this.collection),d.body.sensitive?(s=yield i.findOne({_id:a}),(0,moment_1.default)(d.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(s.baseUpdatedAt))?(o=r(d.body.data),yield i.updateOne({_id:a},{$set:Object.assign({},o)}),c.send({success:!0})):c.status(400).json({err:"Refresh Sensitive Model"})):(n=r(d.body.data),yield i.updateOne({_id:a},{$set:Object.assign({},n)}),c.send({success:!0}))):c.status(400).json({err:"Invalid Security Configuration"})):c.status(400).json({err:"Invalid Model Structure"})}catch(t){c.status(400).json({err:t})}}),this.initDelete=(n,a)=>__awaiter(this,void 0,void 0,function*(){try{var t,e,i,s,o=n.body.id;o?(e=yield(t=this.mongoDB.db(this.tableId).collection(this.collection)).findOne({_id:o}),i=(0,QueryModel_1.checkBaseConfig)(this.config,n),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",n,e),i&&s?(yield t.findOneAndDelete({_id:o}),a.send({success:!0})):a.status(400).json({err:"Invalid Security Configuration"})):a.status(400).json({err:"Invalid Fields"})}catch(t){a.status(400).json({err:t})}}),this.initList=(c,l)=>__awaiter(this,void 0,void 0,function*(){try{var i=(0,QueryModel_1.checkBaseConfig)(this.config,c);if(i){var s=c.body.query;const d={};s&&0<s.length&&s.map(t=>{var e,i=null!=(e=t.queryId)?e:"";const s=t.value;switch(t.type){case"search":t.searchIds&&0<t.searchIds.length&&(d.$or=[],t.searchIds.map(t=>{d.$or.push({[t]:{$regex:s,$options:"i"}})}));break;case"=":d[i]=s;break;case">":d[i]={$gt:s};break;case"<":d[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(d[i]={$gte:s[0],$lte:s[1]});break;case"in":d[i]={$in:s}}});let t=this.mongoDB.db(this.tableId).collection(this.collection).find(d);var o,n,a=yield t.count({}),r=(c.body.cursor&&(t=t.skip(c.body.cursor)),c.body.limit&&(t=t.limit(c.body.limit)),c.body.sort&&(n={[(o=c.body.sort).sortId]:"asc"===o.type?1:-1},t=t.sort(n)),yield t.toArray());let e=!0;0<r.length&&r.map(t=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",c,t)||(e=!1)}),i&&e?l.send({data:r,count:a}):l.status(400).json({err:"Invalid Security Configuration"})}else l.status(400).json({err:"Invalid Security Configuration"})}catch(t){l.status(400).json({err:t})}}),this.init=()=>{var t=this.lib.express.Router();return t.post("/create",this.initCreate),t.post("/get",this.initGet),t.post("/update",this.initUpdate),t.post("/delete",this.initDelete),t.post("/list",this.initList),t},this.mongoDB=t,this.collection=e,this.isProd=i,this.config=s,this.modelChecker=o,this.lib=n;t=this.isProd?"prod":"dev";this.tableId=a?a+"-"+t:t}}exports.MongoWrapper=MongoWrapper;
|
package/dist/apis/security.d.ts
CHANGED
|
@@ -15,6 +15,6 @@ export declare class SecurityMiddleware {
|
|
|
15
15
|
* 2. Check User Role
|
|
16
16
|
* 3. Check API Token
|
|
17
17
|
*/
|
|
18
|
-
init(): (req: any, res: any, next
|
|
18
|
+
init(): (req: any, res: any, next?: any) => Promise<void>;
|
|
19
19
|
}
|
|
20
20
|
//# sourceMappingURL=security.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/apis/security.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,kBAAkB;IAE7B,mBAAmB,UAAW,MAAM,YAElC;IACF,SAAS,WAAY,MAAM,YAEzB;IACF,aAAa,aAAc,MAAM,aAE/B;gBAIA,mBAAmB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAC9C,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,EACrC,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO;IAO9C;;;;OAIG;IACH,IAAI,UAG8C,GAAG,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/apis/security.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,kBAAkB;IAE7B,mBAAmB,UAAW,MAAM,YAElC;IACF,SAAS,WAAY,MAAM,YAEzB;IACF,aAAa,aAAc,MAAM,aAE/B;gBAIA,mBAAmB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAC9C,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,EACrC,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO;IAO9C;;;;OAIG;IACH,IAAI,UAG8C,GAAG,OAAO,GAAG,SAAS,GAAG;CA6B5E"}
|
package/dist/apis/security.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,r,u,d){return new(u=u||Promise)(function(o,t){function i(e){try{c(d.next(e))}catch(e){t(e)}}function n(e){try{c(d.throw(e))}catch(e){t(e)}}function c(e){var t;e.done?o(e.value):((t=e.value)instanceof u?t:new u(function(e){e(t)})).then(i,n)}c((d=d.apply(e,r||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecurityMiddleware=void 0;class SecurityMiddleware{constructor(e,t,o){this.checkAuthentication=e=>"",this.checkRole=e=>"",this.checkAPIToken=e=>!1,this.checkAuthentication=e,this.checkRole=t,this.checkAPIToken=o}init(){const i=this;return function(t,e,o){return __awaiter(this,void 0,void 0,function*(){var e;delete t.body.bm_userId,delete t.body.bm_userRole,delete t.body.bm_apiToken,t.body.userToken&&(e=i.checkAuthentication(t.body.userToken))&&(t.body.bm_userId=e,e=i.checkRole(e))&&(t.body.bm_userRole=e),t.body.apiToken&&(e=t.body.apiToken,e=i.checkAPIToken(e),t.body.bm_apiToken=e),o()})}}}exports.SecurityMiddleware=SecurityMiddleware;
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,r,u,d){return new(u=u||Promise)(function(o,t){function i(e){try{c(d.next(e))}catch(e){t(e)}}function n(e){try{c(d.throw(e))}catch(e){t(e)}}function c(e){var t;e.done?o(e.value):((t=e.value)instanceof u?t:new u(function(e){e(t)})).then(i,n)}c((d=d.apply(e,r||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecurityMiddleware=void 0;class SecurityMiddleware{constructor(e,t,o){this.checkAuthentication=e=>"",this.checkRole=e=>"",this.checkAPIToken=e=>!1,this.checkAuthentication=e,this.checkRole=t,this.checkAPIToken=o}init(){const i=this;return function(t,e,o){return __awaiter(this,void 0,void 0,function*(){var e;delete t.body.bm_userId,delete t.body.bm_userRole,delete t.body.bm_apiToken,t.body.userToken&&(e=i.checkAuthentication(t.body.userToken))&&(t.body.bm_userId=e,e=i.checkRole(e))&&(t.body.bm_userRole=e),t.body.apiToken&&(e=t.body.apiToken,e=i.checkAPIToken(e),t.body.bm_apiToken=e),o&&o()})}}}exports.SecurityMiddleware=SecurityMiddleware;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "blixify-server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/apis/index.js",
|
|
6
6
|
"private": false,
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
14
|
"clean": "rm -rf ./dist",
|
|
15
|
+
"clean:windows": "rmdir /s dist",
|
|
15
16
|
"prebuild": "yarn clean",
|
|
16
17
|
"predeploy": "yarn clean",
|
|
17
18
|
"postbuild": "./minify-js.sh",
|