blixify-server 0.1.3 → 0.1.5

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.
@@ -1,3 +1,4 @@
1
1
  export { FirebaseWrapper } from "./fbWrapper";
2
2
  export { MongoWrapper } from "./mongoWrapper";
3
+ export { SecurityMiddleware } from "./security";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/apis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/apis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MongoWrapper=exports.FirebaseWrapper=void 0;var fbWrapper_1=require("./fbWrapper"),mongoWrapper_1=(Object.defineProperty(exports,"FirebaseWrapper",{enumerable:!0,get:function(){return fbWrapper_1.FirebaseWrapper}}),require("./mongoWrapper"));Object.defineProperty(exports,"MongoWrapper",{enumerable:!0,get:function(){return mongoWrapper_1.MongoWrapper}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecurityMiddleware=exports.MongoWrapper=exports.FirebaseWrapper=void 0;var fbWrapper_1=require("./fbWrapper"),mongoWrapper_1=(Object.defineProperty(exports,"FirebaseWrapper",{enumerable:!0,get:function(){return fbWrapper_1.FirebaseWrapper}}),require("./mongoWrapper")),security_1=(Object.defineProperty(exports,"MongoWrapper",{enumerable:!0,get:function(){return mongoWrapper_1.MongoWrapper}}),require("./security"));Object.defineProperty(exports,"SecurityMiddleware",{enumerable:!0,get:function(){return security_1.SecurityMiddleware}});
@@ -1 +1 @@
1
- {"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAOA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IAEF,YAAY,QAAS,GAAG,aAEtB;gBAGA,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;IASvD,IAAI,YA8SF;CACH"}
1
+ {"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAOA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAIrD;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IAEF,YAAY,QAAS,GAAG,aAEtB;gBAGA,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;IASvD,IAAI,YA8SF;CACH"}
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,n,d,a){return new(d=d||Promise)(function(o,t){function i(e){try{r(a.next(e))}catch(e){t(e)}}function s(e){try{r(a.throw(e))}catch(e){t(e)}}function r(e){var t;e.done?o(e.value):((t=e.value)instanceof d?t:new d(function(e){e(t)})).then(i,s)}r((a=a.apply(e,n||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MongoWrapper=void 0;const moment_1=__importDefault(require("moment")),QueryModel_1=require("../model/QueryModel"),express=require("express");class MongoWrapper{constructor(e,t,o,i,s){this.mongoDB="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.init=()=>{var e=express.Router();return e.post("/create",(o,i)=>__awaiter(this,void 0,void 0,function*(){try{var e,t;this.modelChecker(o.body.data)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,o),t=(0,QueryModel_1.checkOpsConfig)(this.config,"create",o,o.body.data),e&&t?(o.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),yield this.mongoDB.db(this.isProd?"prod":"dev").collection(this.collection).insertOne(o.body.data),i.send({success:!0})):i.status(400).json({err:"Invalid Security Configuration"})):i.status(400).json({err:"Invalid Model Structure"})}catch(e){i.status(400).json({err:e})}})),e.post("/get",(s,r)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,o,i=s.body.id;i?(e=yield this.mongoDB.db(this.isProd?"prod":"dev").collection(this.collection).findOne({_id:i}),t=(0,QueryModel_1.checkBaseConfig)(this.config,s),o=(0,QueryModel_1.checkOpsConfig)(this.config,"read",s,e),t&&o?r.send({data:e}):r.status(400).json({err:"Invalid Security Configuration"})):r.status(400).json({err:"Invalid Fields"})}catch(e){r.status(400).json({err:e})}})),e.post("/update",(a,c)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,o,i,s,r,n=this.modelChecker(a.body.data)&&a.body.id,d=e=>(delete e._id,e.baseUpdatedAt=(0,moment_1.default)().toDate(),e);n?(e=(0,QueryModel_1.checkBaseConfig)(this.config,a),t=(0,QueryModel_1.checkOpsConfig)(this.config,"update",a,a.body.data),e&&t?(o=this.mongoDB.db(this.isProd?"prod":"dev").collection(this.collection),a.body.sensitive?(i=yield o.findOne({_id:n}),(0,moment_1.default)(a.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(i.baseUpdatedAt))?(s=d(a.body.data),yield o.updateOne({_id:n},{$set:Object.assign({},s)}),c.send({success:!0})):c.status(400).json({err:"Refresh Sensitive Model"})):(r=d(a.body.data),yield o.updateOne({_id:n},{$set:Object.assign({},r)}),c.send({success:!0}))):c.status(400).json({err:"Invalid Security Configuration"})):c.status(400).json({err:"Invalid Model Structure"})}catch(e){c.status(400).json({err:e})}})),e.post("/delete",(r,n)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,o,i,s=r.body.id;s?(t=yield(e=this.mongoDB.db(this.isProd?"prod":"dev").collection(this.collection)).findOne({_id:s}),o=(0,QueryModel_1.checkBaseConfig)(this.config,r),i=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",r,t),o&&i?(yield e.findOneAndDelete({_id:s}),n.send({success:!0})):n.status(400).json({err:"Invalid Security Configuration"})):n.status(400).json({err:"Invalid Fields"})}catch(e){n.status(400).json({err:e})}})),e.post("/list",(c,l)=>__awaiter(this,void 0,void 0,function*(){try{var o=(0,QueryModel_1.checkBaseConfig)(this.config,c);if(o){var i=c.body.query;const a={};i&&0<i.length&&i.map(e=>{var t,o=null!=(t=e.queryId)?t:"";const i=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(a.$or=[],e.searchIds.map(e=>{a.$or.push({[e]:{$regex:i,$options:"i"}})}));break;case"=":a[o]=i;break;case">":a[o]={$gt:i};break;case"<":a[o]={$lt:i};break;case"><":Array.isArray(i)&&2<=i.length&&(a[o]={$gte:i[0],$lte:i[1]});break;case"in":a[o]={$in:i}}});let e=this.mongoDB.db(this.isProd?"prod":"dev").collection(this.collection).find(a);var s,r,n=yield e.count({}),d=(c.body.cursor&&(e=e.skip(c.body.cursor)),c.body.limit&&(e=e.limit(c.body.limit)),c.body.sort&&(r={[(s=c.body.sort).sortId]:"asc"===s.type?1:-1},e=e.sort(r)),yield e.toArray());let t=!0;0<d.length&&d.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",c,e)||(t=!1)}),o&&t?l.send({data:d,count:n}):l.status(400).json({err:"Invalid Security Configuration"})}else l.status(400).json({err:"Invalid Security Configuration"})}catch(e){l.status(400).json({err:e})}})),e},this.mongoDB=e,this.collection=t,this.isProd=o,this.config=i,this.modelChecker=s}}exports.MongoWrapper=MongoWrapper;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,d,n,a){return new(n=n||Promise)(function(o,t){function i(e){try{r(a.next(e))}catch(e){t(e)}}function s(e){try{r(a.throw(e))}catch(e){t(e)}}function r(e){var t;e.done?o(e.value):((t=e.value)instanceof n?t:new n(function(e){e(t)})).then(i,s)}r((a=a.apply(e,d||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MongoWrapper=void 0;const moment_1=__importDefault(require("moment")),QueryModel_1=require("../model/QueryModel"),express=require("express"),ObjectId=require("mongodb")["ObjectId"];class MongoWrapper{constructor(e,t,o,i,s){this.mongoDB="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.init=()=>{var e=express.Router();return e.post("/create",(o,i)=>__awaiter(this,void 0,void 0,function*(){try{var e,t;this.modelChecker(o.body.data)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,o),t=(0,QueryModel_1.checkOpsConfig)(this.config,"create",o,o.body.data),e&&t?(o.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),yield this.mongoDB.db(this.isProd?"prod":"dev").collection(this.collection).insertOne(o.body.data),i.send({success:!0})):i.status(400).json({err:"Invalid Security Configuration"})):i.status(400).json({err:"Invalid Model Structure"})}catch(e){i.status(400).json({err:e})}})),e.post("/get",(s,r)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,o,i=s.body.id;i?(e=yield this.mongoDB.db(this.isProd?"prod":"dev").collection(this.collection).findOne({_id:ObjectId(i)}),t=(0,QueryModel_1.checkBaseConfig)(this.config,s),o=(0,QueryModel_1.checkOpsConfig)(this.config,"read",s,e),t&&o?r.send({data:e}):r.status(400).json({err:"Invalid Security Configuration"})):r.status(400).json({err:"Invalid Fields"})}catch(e){r.status(400).json({err:e})}})),e.post("/update",(a,c)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,o,i,s,r,d=this.modelChecker(a.body.data)&&a.body.id,n=e=>(delete e._id,e.baseUpdatedAt=(0,moment_1.default)().toDate(),e);d?(e=(0,QueryModel_1.checkBaseConfig)(this.config,a),t=(0,QueryModel_1.checkOpsConfig)(this.config,"update",a,a.body.data),e&&t?(o=this.mongoDB.db(this.isProd?"prod":"dev").collection(this.collection),a.body.sensitive?(i=yield o.findOne({_id:ObjectId(d)}),(0,moment_1.default)(a.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(i.baseUpdatedAt))?(s=n(a.body.data),yield o.updateOne({_id:ObjectId(d)},{$set:Object.assign({},s)}),c.send({success:!0})):c.status(400).json({err:"Refresh Sensitive Model"})):(r=n(a.body.data),yield o.updateOne({_id:ObjectId(d)},{$set:Object.assign({},r)}),c.send({success:!0}))):c.status(400).json({err:"Invalid Security Configuration"})):c.status(400).json({err:"Invalid Model Structure"})}catch(e){c.status(400).json({err:e})}})),e.post("/delete",(r,d)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,o,i,s=r.body.id;s?(t=yield(e=this.mongoDB.db(this.isProd?"prod":"dev").collection(this.collection)).findOne({_id:ObjectId(s)}),o=(0,QueryModel_1.checkBaseConfig)(this.config,r),i=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",r,t),o&&i?(yield e.findOneAndDelete({_id:ObjectId(s)}),d.send({success:!0})):d.status(400).json({err:"Invalid Security Configuration"})):d.status(400).json({err:"Invalid Fields"})}catch(e){d.status(400).json({err:e})}})),e.post("/list",(c,l)=>__awaiter(this,void 0,void 0,function*(){try{var o=(0,QueryModel_1.checkBaseConfig)(this.config,c);if(o){var i=c.body.query;const a={};i&&0<i.length&&i.map(e=>{var t,o=null!=(t=e.queryId)?t:"";const i=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(a.$or=[],e.searchIds.map(e=>{a.$or.push({[e]:{$regex:i,$options:"i"}})}));break;case"=":a[o]=i;break;case">":a[o]={$gt:i};break;case"<":a[o]={$lt:i};break;case"><":Array.isArray(i)&&2<=i.length&&(a[o]={$gte:i[0],$lte:i[1]});break;case"in":a[o]={$in:i}}});let e=this.mongoDB.db(this.isProd?"prod":"dev").collection(this.collection).find(a);var s,r,d=yield e.count({}),n=(c.body.cursor&&(e=e.skip(c.body.cursor)),c.body.limit&&(e=e.limit(c.body.limit)),c.body.sort&&(r={[(s=c.body.sort).sortId]:"asc"===s.type?1:-1},e=e.sort(r)),yield e.toArray());let t=!0;0<n.length&&n.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",c,e)||(t=!1)}),o&&t?l.send({data:n,count:d}):l.status(400).json({err:"Invalid Security Configuration"})}else l.status(400).json({err:"Invalid Security Configuration"})}catch(e){l.status(400).json({err:e})}})),e},this.mongoDB=e,this.collection=t,this.isProd=o,this.config=i,this.modelChecker=s}}exports.MongoWrapper=MongoWrapper;
@@ -5,7 +5,7 @@
5
5
  * 3. Basic helmet security configurations
6
6
  * 4. Prevent DDOS from rate limiting
7
7
  */
8
- export default class SecurityMiddleware {
8
+ export declare class SecurityMiddleware {
9
9
  checkAuthentication: (token: string) => string;
10
10
  checkRole: (userId: string) => string;
11
11
  checkAPIToken: (apiToken: string) => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/apis/security.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAkB;IAErC,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,QAAQ,GAAG;CA2B3E"}
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,QAAQ,GAAG;CA2B3E"}
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,r,u,a){return new(u=u||Promise)(function(o,t){function n(e){try{c(a.next(e))}catch(e){t(e)}}function i(e){try{c(a.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(n,i)}c((a=a.apply(e,r||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!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 n=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=n.checkAuthentication(t.body.userToken))&&(t.body.bm_userId=e,e=n.checkRole(e))&&(t.body.bm_userRole=e),t.body.apiToken&&(e=t.body.apiToken,e=n.checkAPIToken(e),t.body.bm_apiToken=e),o()})}}}exports.default=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()})}}}exports.SecurityMiddleware=SecurityMiddleware;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blixify-server",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "license": "MIT",
5
5
  "main": "dist/apis/index.js",
6
6
  "private": false,