blixify-server 0.1.23 → 0.1.25

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,8 +1,5 @@
1
1
  import SecurityConfig from "../model/SecurityConfig";
2
- export interface WrapperLib {
3
- express?: any;
4
- axios?: any;
5
- }
2
+ import { WrapperLib } from "./mongoWrapper";
6
3
  export declare const queryMondayApi: (token: string, query: any, variables?: any) => Promise<import("axios").AxiosResponse<any, any>>;
7
4
  /**
8
5
  * @Wrapper
@@ -1 +1 @@
1
- {"version":3,"file":"mondayWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mondayWrapper.ts"],"names":[],"mappings":"AAEA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED,eAAO,MAAM,cAAc,UAClB,MAAM,SACN,GAAG,cACE,GAAG,qDAahB,CAAC;AAEF;;;;GAIG;AACH,qBAAa,aAAa;IACxB,WAAW,SAAM;IACjB,OAAO,SAAM;IACb,OAAO,SAAM;IACb,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAEhB,YAAY,QAAS,GAAG,aAEtB;IACF,SAAS;cAAe,MAAM,EAAE;;;;MAK9B;gBAGA,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,SAAS,EAAE,MAAM;QAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE;YAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAA;KAAE,EACpE,GAAG,EAAE,UAAU;IAWjB,UAAU,eAAgB;QACxB,EAAE,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AAM;IAYlB,UAAU,SAAU,GAAG,SAIrB;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCAiD5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA+BtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA8BjC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBAuEzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA4DpC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCAuH5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCAmCtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBAyOlC;IAEF,IAAI,YA0EF;CACH"}
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,n,d,r){return new(d=d||Promise)(function(i,t){function s(e){try{o(r.next(e))}catch(e){t(e)}}function a(e){try{o(r.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?i(e.value):((t=e.value)instanceof d?t:new d(function(e){e(t)})).then(s,a)}o((r=r.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");class MongoWrapper{constructor(e,t,i,s,a,o,n){this.mongoDB="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.tableId="",this.parseModel=e=>(delete e._id,e.baseUpdatedAt=(0,moment_1.default)().toDate(),e),this.initBatchCreate=(a,o,n)=>__awaiter(this,void 0,void 0,function*(){try{if(Array.isArray(a.body.data)){let t=!0;a.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t||o.status(400).json({err:"Invalid Model Structure"});var e,s=(0,QueryModel_1.checkBaseConfig)(this.config,a);let i=!0;yield Promise.all(a.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",a,e)||(i=!1)})),s&&i?(e=a.body.data.map(e=>Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_1.default)().toDate()})),n&&(yield n(e)),yield this.mongoDB.db(this.tableId).collection(this.collection).insertMany(e),o.send({success:!0})):o.status(400).json({err:"Invalid Security Configuration"})}else o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.initCreate=(i,s,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t;this.modelChecker(i.body.data)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,i),t=(0,QueryModel_1.checkOpsConfig)(this.config,"create",i,i.body.data),e&&t?(i.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),a&&(yield a(i.body.data)),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(e){s.status(400).json({err:e})}}),this.initGet=(a,o)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s=a.body.id;s?(e=yield this.mongoDB.db(this.tableId).collection(this.collection).findOne({_id:s}),t=(0,QueryModel_1.checkBaseConfig)(this.config,a),i=(0,QueryModel_1.checkOpsConfig)(this.config,"read",a,e),t&&i?o.send({data:e}):o.status(400).json({err:"Invalid Security Configuration"})):o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.initBatchUpdate=(o,n)=>__awaiter(this,void 0,void 0,function*(){try{var e=this.modelChecker(o.body.data)&&o.body.id;if(Array.isArray(o.body.id)){var s=o.body.data.map(e=>Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_1.default)().toDate()})),i=(0,QueryModel_1.checkBaseConfig)(this.config,o);let t=!0;if(yield Promise.all(o.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",o,e)||(t=!1)})),i&&t){const a=this.mongoDB.db(this.tableId).collection(this.collection);if(o.body.sensitive){let i=!0;yield Promise.all(o.body.id.map(t=>__awaiter(this,void 0,void 0,function*(){var e=yield a.findOne({_id:t});(0,moment_1.default)(o.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(e.baseUpdatedAt))?n.status(400).json({err:"Refresh Sensitive Model"}):i=!1}))),i&&(yield a.updateMany({_id:{$in:e}},{$set:Object.assign({},s)}),n.send({success:!0}))}else yield a.updateMany({_id:{$in:e}},{$set:Object.assign({},s)}),n.send({success:!0})}else n.status(400).json({err:"Invalid Security Configuration"})}}catch(e){}}),this.initUpdate=(d,r)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,a,o,n=this.modelChecker(d.body.data)&&d.body.id;n?(e=(0,QueryModel_1.checkBaseConfig)(this.config,d),t=(0,QueryModel_1.checkOpsConfig)(this.config,"update",d,d.body.data),e&&t?(i=this.mongoDB.db(this.tableId).collection(this.collection),d.body.sensitive?(s=yield i.findOne({_id:n}),(0,moment_1.default)(d.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(s.baseUpdatedAt))?(a=this.parseModel(d.body.data),yield i.updateOne({_id:n},{$set:Object.assign({},a)}),r.send({success:!0})):r.status(400).json({err:"Refresh Sensitive Model"})):(o=this.parseModel(d.body.data),yield i.updateOne({_id:n},{$set:Object.assign({},o)}),r.send({success:!0}))):r.status(400).json({err:"Invalid Security Configuration"})):r.status(400).json({err:"Invalid Model Structure"})}catch(e){r.status(400).json({err:e})}}),this.initBatchDelete=(c,u,h)=>__awaiter(this,void 0,void 0,function*(){try{if(Array.isArray(c.body.id)){var e=this.mongoDB.db(this.tableId).collection(this.collection),i=yield e.find({_id:{$in:c.body.id}}),s=(0,QueryModel_1.checkBaseConfig)(this.config,c),a=yield i.toArray();let t=!0;0<a.length&&(yield Promise.all(a.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}))),s&&t?(h&&(yield h(a)),yield e.deleteMany({_id:{$in:c.body.id}}),u.send({success:!0})):u.status(400).json({err:"Invalid Security Configuration"})}else{var o=c.body.query;const l={};o&&0<o.length&&o.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(l.$or=[],e.searchIds.map(e=>{l.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":l[i]=s;break;case"!=":l[i]={$ne:s};break;case">":l[i]={$gt:s};break;case"<":l[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(l[i]={$gte:s[0],$lte:s[1]});break;case"in":l[i]={$in:s}}});var n=this.mongoDB.db(this.tableId).collection(this.collection),d=yield n.find(l).toArray(),r=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;0<d.length&&d.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}),h&&(yield h(d)),r&&t?(yield n.deleteMany(l),u.send({success:!0})):u.status(400).json({err:"Invalid Security Configuration"})}}catch(e){u.status(400).json({err:e})}}),this.initDelete=(o,n,d)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,a=o.body.id;a?(t=yield(e=this.mongoDB.db(this.tableId).collection(this.collection)).findOne({_id:a}),i=(0,QueryModel_1.checkBaseConfig)(this.config,o),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",o,t),i&&s?(d&&(yield d(t)),yield e.findOneAndDelete({_id:a}),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})}}),this.initList=(A,B)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s,a,o;try{var n=(0,QueryModel_1.checkBaseConfig)(this.config,A);if(n){var d=A.body.aggregate,r=null!=(e=A.body.query)?e:[];const Y={};if(r&&0<r.length&&r.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(Y.$or=[],e.searchIds.map(e=>{Y.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":Y[i]=s;break;case"!=":Y[i]={$ne:s};break;case">":Y[i]={$gt:s};break;case"<":Y[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(Y[i]={$gte:s[0],$lte:s[1]});break;case"in":Y[i]={$in:s}}}),d){var l=[],c=null!=(t=d.queryId)?t:"",u=null!=(i=d.dateId)?i:"baseUpdatedAt";for(const O of null!=(s=d.range)?s:[]){Object.assign({},Y);var h=O.split("-"),[y,g=(0,moment_1.default)().format("DD/MM/YYYY HH:mm:ss")]=h,f=2===h.length,b=(0,moment_1.default)(y,"DD/MM/YYYY").isValid(),m=(0,moment_1.default)(g,"DD/MM/YYYY").isValid(),p=(0,moment_1.default)(y,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss"),v=(0,moment_1.default)(g,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");if(!b||!m)return void B.status(400).json({err:"Invalid Aggregate Range Configuration"});var _=f?{$match:Object.assign(Object.assign({},Y),{[u]:{$gte:new Date(p),$lte:new Date(v)}})}:{$match:Object.assign(Object.assign({},Y),{[u]:{$lte:new Date(p)}})},M=[];let e=!1;var D=f?O:"Begining until "+(0,moment_1.default)(y).format("DD/MM/YYYY");switch(d.type){case"avg":M.push(_,{$group:{_id:D,value:{$avg:"$"+c}}});break;case"sum":M.push(_,{$group:{_id:D,value:{$sum:"$"+c}}});break;case"count":e=!0}if(0===M.length&&!e)return void B.status(400).json({err:"Invalid Aggregate Configuration"});var C=this.mongoDB.db(this.tableId).collection(this.collection);let t=0;t=e?yield C.find(Y).count({}):null!=(o=null==(a=(yield C.aggregate(M).toArray())[0])?void 0:a.value)?o:0,l.push({_id:D,value:t})}B.send({data:l})}else{let e=this.mongoDB.db(this.tableId).collection(this.collection).find(Y);var j,I,k=yield e.count({}),$=(A.body.cursor&&(e=e.skip(A.body.cursor)),A.body.limit&&(e=e.limit(A.body.limit)),A.body.sort&&(I={[(j=A.body.sort).sortId]:"asc"===j.type?1:-1},e=e.sort(I)),yield e.toArray());let t=!0;0<$.length&&$.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",A,e)||(t=!1)}),n&&t?B.send({data:$,count:k}):B.status(400).json({err:"Invalid Security Configuration"})}}else B.status(400).json({err:"Invalid Security Configuration"})}catch(e){B.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",(e,t)=>{this.initCreate(e,t)}),e.post("/batchCreate",(e,t)=>{this.initBatchCreate(e,t)}),e.post("/get",(e,t)=>{this.initGet(e,t)}),e.post("/update",(e,t)=>{this.initUpdate(e,t)}),e.post("/batchUpdate",(e,t)=>{this.initBatchUpdate(e,t)}),e.post("/delete",(e,t)=>{this.initDelete(e,t)}),e.post("/batchDelete",(e,t)=>{this.initBatchDelete(e,t)}),e.post("/list",(e,t)=>{this.initList(e,t)}),e},this.mongoDB=e,this.collection=t,this.isProd=i,this.config=s,this.modelChecker=a,this.lib=o;e=this.isProd?"prod":"dev";this.tableId=n?n+"-"+e:e}}exports.MongoWrapper=MongoWrapper;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,n,d,r){return new(d=d||Promise)(function(i,t){function s(e){try{o(r.next(e))}catch(e){t(e)}}function a(e){try{o(r.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?i(e.value):((t=e.value)instanceof d?t:new d(function(e){e(t)})).then(s,a)}o((r=r.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");class MongoWrapper{constructor(e,t,i,s,a,o,n){this.mongoDB="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.tableId="",this.parseModel=e=>(delete e._id,e.baseUpdatedAt=(0,moment_1.default)().toDate(),e),this.initBatchCreate=(a,o,n)=>__awaiter(this,void 0,void 0,function*(){try{if(Array.isArray(a.body.data)){let t=!0;a.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t||o.status(400).json({err:"Invalid Model Structure"});var e,s=(0,QueryModel_1.checkBaseConfig)(this.config,a);let i=!0;yield Promise.all(a.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",a,e)||(i=!1)})),s&&i?(e=a.body.data.map(e=>Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_1.default)().toDate()})),n&&(yield n(e)),yield this.mongoDB.db(this.tableId).collection(this.collection).insertMany(e),o.send({success:!0})):o.status(400).json({err:"Invalid Security Configuration"})}else o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.initCreate=(i,s,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t;this.modelChecker(i.body.data)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,i),t=(0,QueryModel_1.checkOpsConfig)(this.config,"create",i,i.body.data),e&&t?(i.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),a&&(yield a(i.body.data)),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(e){s.status(400).json({err:e})}}),this.initGet=(a,o)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s=a.body.id;s?(e=yield this.mongoDB.db(this.tableId).collection(this.collection).findOne({_id:s}),t=(0,QueryModel_1.checkBaseConfig)(this.config,a),i=(0,QueryModel_1.checkOpsConfig)(this.config,"read",a,e),t&&i?o.send({data:e}):o.status(400).json({err:"Invalid Security Configuration"})):o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.initBatchUpdate=(o,n)=>__awaiter(this,void 0,void 0,function*(){try{var e=this.modelChecker(o.body.data)&&o.body.id;if(Array.isArray(o.body.id)){var s=o.body.data.map(e=>Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_1.default)().toDate()})),i=(0,QueryModel_1.checkBaseConfig)(this.config,o);let t=!0;if(yield Promise.all(o.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",o,e)||(t=!1)})),i&&t){const a=this.mongoDB.db(this.tableId).collection(this.collection);if(o.body.sensitive){let i=!0;yield Promise.all(o.body.id.map(t=>__awaiter(this,void 0,void 0,function*(){var e=yield a.findOne({_id:t});(0,moment_1.default)(o.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(e.baseUpdatedAt))?n.status(400).json({err:"Refresh Sensitive Model"}):i=!1}))),i&&(yield a.updateMany({_id:{$in:e}},{$set:Object.assign({},s)}),n.send({success:!0}))}else yield a.updateMany({_id:{$in:e}},{$set:Object.assign({},s)}),n.send({success:!0})}else n.status(400).json({err:"Invalid Security Configuration"})}}catch(e){}}),this.initUpdate=(d,r)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,a,o,n=this.modelChecker(d.body.data)&&d.body.id;n?(e=(0,QueryModel_1.checkBaseConfig)(this.config,d),t=(0,QueryModel_1.checkOpsConfig)(this.config,"update",d,d.body.data),e&&t?(i=this.mongoDB.db(this.tableId).collection(this.collection),d.body.sensitive?(s=yield i.findOne({_id:n}),(0,moment_1.default)(d.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(s.baseUpdatedAt))?(a=this.parseModel(d.body.data),yield i.updateOne({_id:n},{$set:Object.assign({},a)}),r.send({success:!0})):r.status(400).json({err:"Refresh Sensitive Model"})):(o=this.parseModel(d.body.data),yield i.updateOne({_id:n},{$set:Object.assign({},o)}),r.send({success:!0}))):r.status(400).json({err:"Invalid Security Configuration"})):r.status(400).json({err:"Invalid Model Structure"})}catch(e){r.status(400).json({err:e})}}),this.initBatchDelete=(c,h,u)=>__awaiter(this,void 0,void 0,function*(){try{if(Array.isArray(c.body.id)){var e=this.mongoDB.db(this.tableId).collection(this.collection),i=yield e.find({_id:{$in:c.body.id}}),s=(0,QueryModel_1.checkBaseConfig)(this.config,c),a=yield i.toArray();let t=!0;0<a.length&&(yield Promise.all(a.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}))),s&&t?(u&&(yield u(a)),yield e.deleteMany({_id:{$in:c.body.id}}),h.send({success:!0})):h.status(400).json({err:"Invalid Security Configuration"})}else{var o=c.body.query;const l={};o&&0<o.length&&o.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(l.$or=[],e.searchIds.map(e=>{l.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":l[i]=s;break;case"!=":l[i]={$ne:s};break;case">":l[i]={$gt:s};break;case"<":l[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(l[i]={$gte:s[0],$lte:s[1]});break;case"in":l[i]={$in:s}}});var n=this.mongoDB.db(this.tableId).collection(this.collection),d=yield n.find(l).toArray(),r=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;0<d.length&&d.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}),u&&(yield u(d)),r&&t?(yield n.deleteMany(l),h.send({success:!0})):h.status(400).json({err:"Invalid Security Configuration"})}}catch(e){h.status(400).json({err:e})}}),this.initDelete=(o,n,d)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,a=o.body.id;a?(t=yield(e=this.mongoDB.db(this.tableId).collection(this.collection)).findOne({_id:a}),i=(0,QueryModel_1.checkBaseConfig)(this.config,o),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",o,t),i&&s?(d&&(yield d(t)),yield e.findOneAndDelete({_id:a}),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})}}),this.initList=(A,B)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s,a,o;try{var n=(0,QueryModel_1.checkBaseConfig)(this.config,A);if(n){var d=A.body.aggregate,r=null!=(e=A.body.query)?e:[];const Y={};if(r&&0<r.length&&r.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(Y.$or=[],e.searchIds.map(e=>{Y.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":Y[i]=s;break;case"!=":Y[i]={$ne:s};break;case">":Y[i]={$gt:s};break;case"<":Y[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(Y[i]={$gte:s[0],$lte:s[1]});break;case"in":Y[i]={$in:s}}}),d){var l=[],c=null!=(t=d.queryId)?t:"",h=null!=(i=d.dateId)?i:"baseUpdatedAt";for(const O of null!=(s=d.range)?s:[]){Object.assign({},Y);var u=O.split("-"),[y,g=(0,moment_1.default)().format("DD/MM/YYYY HH:mm:ss")]=u,f=2===u.length,b=(0,moment_1.default)(y,"DD/MM/YYYY").isValid(),m=(0,moment_1.default)(g,"DD/MM/YYYY").isValid(),p=(0,moment_1.default)(y,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss"),v=(0,moment_1.default)(g,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");if(!b||!m)return void B.status(400).json({err:"Invalid Aggregate Range Configuration"});var _=f?{$match:Object.assign(Object.assign({},Y),{[h]:{$gte:new Date(p),$lte:new Date(v)}})}:{$match:Object.assign(Object.assign({},Y),{[h]:{$lte:new Date(p)}})},M=[];let e=!1;var D=f?O:"Begining until "+(0,moment_1.default)(y,"DD/MM/YYYY HH:mm:ss").format("DD/MM/YYYY");switch(d.type){case"avg":M.push(_,{$group:{_id:D,value:{$avg:"$"+c}}});break;case"sum":M.push(_,{$group:{_id:D,value:{$sum:"$"+c}}});break;case"count":e=!0}if(0===M.length&&!e)return void B.status(400).json({err:"Invalid Aggregate Configuration"});var C=this.mongoDB.db(this.tableId).collection(this.collection);let t=0;t=e?yield C.find(_.$match).count({}):null!=(o=null==(a=(yield C.aggregate(M).toArray())[0])?void 0:a.value)?o:0,l.push({_id:D,value:t})}B.send({data:l})}else{let e=this.mongoDB.db(this.tableId).collection(this.collection).find(Y);var j,I,$=yield e.count({}),k=(A.body.cursor&&(e=e.skip(A.body.cursor)),A.body.limit&&(e=e.limit(A.body.limit)),A.body.sort&&(I={[(j=A.body.sort).sortId]:"asc"===j.type?1:-1},e=e.sort(I)),yield e.toArray());let t=!0;0<k.length&&k.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",A,e)||(t=!1)}),n&&t?B.send({data:k,count:$}):B.status(400).json({err:"Invalid Security Configuration"})}}else B.status(400).json({err:"Invalid Security Configuration"})}catch(e){B.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",(e,t)=>{this.initCreate(e,t)}),e.post("/batchCreate",(e,t)=>{this.initBatchCreate(e,t)}),e.post("/get",(e,t)=>{this.initGet(e,t)}),e.post("/update",(e,t)=>{this.initUpdate(e,t)}),e.post("/batchUpdate",(e,t)=>{this.initBatchUpdate(e,t)}),e.post("/delete",(e,t)=>{this.initDelete(e,t)}),e.post("/batchDelete",(e,t)=>{this.initBatchDelete(e,t)}),e.post("/list",(e,t)=>{this.initList(e,t)}),e},this.mongoDB=e,this.collection=t,this.isProd=i,this.config=s,this.modelChecker=a,this.lib=o;e=this.isProd?"prod":"dev";this.tableId=n?n+"-"+e:e}}exports.MongoWrapper=MongoWrapper;
@@ -3,7 +3,7 @@ interface UploadLib {
3
3
  multer: any;
4
4
  randomUUID: any;
5
5
  express?: any;
6
- axios?: any;
6
+ cors?: any;
7
7
  }
8
8
  /**
9
9
  * @Wrapper
@@ -1 +1 @@
1
- {"version":3,"file":"uploadWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/uploadWrapper.ts"],"names":[],"mappings":"AAC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CAQpB;IACF,GAAG,EAAE,SAAS,CAAC;IACf,WAAW,SAAc;IAEzB,YAAY,QAAS,GAAG,sBAAsB,OAAO,aAUnD;gBAGA,WAAW,EAAE,GAAG,EAChB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,SAAS,EACd,WAAW,CAAC,EAAE,UAAU,GAAG,KAAK;IASlC,UAAU,QAAe,GAAG,OAAO,GAAG,QAAQ,QAAQ,GAAG,QAAQ,mBAkG/D;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAuCpC;IAEF,0BAA0B,cAAqB,GAAG,mBAwBhD;IAEF,sBAAsB,eACR,MAAM,mBACD,MAAM,mBAiBvB;IAEF,mBAAmB,QAAe,GAAG,OAAO,GAAG,mBAqC7C;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBAgCjC;IAEF,IAAI,YAqEF;CACH"}
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,d){return new(r=r||Promise)(function(i,t){function s(e){try{o(d.next(e))}catch(e){t(e)}}function a(e){try{o(d.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(s,a)}o((d=d.apply(e,n||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.UploadWrapper=void 0;const QueryModel_1=require("../model/QueryModel");class UploadWrapper{constructor(e,t,i,s,a){this.uploadAdmin="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.storageType="firebase",this.modelChecker=(e,t)=>!(!e.assetCollectionName||!e.assetParentId||!t&&!e.assetFileName),this.initUpload=(l,c,u)=>__awaiter(this,void 0,void 0,function*(){try{const n=l.body.data;if(this.modelChecker(n)&&(l.file||n.downloadLink)){var e=(0,QueryModel_1.checkBaseConfig)(this.config,l),t=(0,QueryModel_1.checkOpsConfig)(this.config,u,l,n);if(e&&t){const r=this.lib.randomUUID();if("aws"===this.storageType){var i,s=(a,o)=>new Promise((i,s)=>__awaiter(this,void 0,void 0,function*(){var e="buffer"===a,t=new this.uploadAdmin.S3,e={Bucket:`${n.bucketName}/${n.assetCollectionName}/`+n.assetParentId,Key:e?n.assetFileName:l.file.originalname,Body:e?o.data:l.file.buffer};t.upload(e,function(e){e?s(e):i("aws")})}));n.downloadLink?(i=yield this.lib.axios({method:"GET",url:n.downloadLink,responseType:"arraybuffer"})).data&&(yield s("buffer",i)):yield s("file")}else{const d=this.uploadAdmin.storage().bucket();var a,o=(a,o)=>new Promise((i,s)=>__awaiter(this,void 0,void 0,function*(){var e="buffer"===a,t={contentType:e?o.headers["content-type"]:l.file.mimetype,customMetadata:{"file-name":"buffer"===a?n.assetFileName:l.file.originalname},metadata:{firebaseStorageDownloadTokens:r}},t=d.file(`${n.assetCollectionName}/${n.assetParentId}/`+n.assetFileName).createWriteStream({metadata:t});t.end(e?o.data:l.file.buffer),t.on("error",s),t.on("finish",i)}));n.downloadLink?(a=yield this.lib.axios({method:"GET",url:n.downloadLink,responseType:"arraybuffer"})).data&&(yield o("buffer",a)):yield o("file")}c.send({data:r})}else c.status(400).json({err:"Invalid Security Configuration"})}else c.status(400).json({err:"Invalid Fields"})}catch(e){c.status(400).json({err:e})}}),this.initDelete=(o,n)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,a=o.body.data;this.modelChecker(a)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,o),t=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",o,a),e&&t?("aws"===this.storageType?(i=new this.uploadAdmin.S3,s={Bucket:`${a.bucketName}/${a.assetCollectionName}/`+a.assetParentId,Key:a.assetFileName},yield i.deleteObject(s).promise()):yield this.uploadAdmin.storage().bucket().file(`${a.assetCollectionName}/${a.assetParentId}/`+a.assetFileName).delete(),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})}}),this.deleteGoogleFolderContents=o=>__awaiter(this,void 0,void 0,function*(){try{var e={prefix:o.name,autoPaginate:!1},[t]=yield this.uploadAdmin.storage().bucket().getFiles(e),i=[];for(const s of t)i.push(s.delete());for(const a of t)a.name.endsWith("/")&&i.push(this.deleteGoogleFolderContents(a));yield Promise.all(i)}catch(e){}}),this.deleteAWSFolderContent=(a,o)=>__awaiter(this,void 0,void 0,function*(){try{var e=new this.uploadAdmin.S3,t=(yield e.listObjectsV2({Bucket:a,Prefix:o}).promise()).Contents.map(e=>e.Key),i=[];for(const s of t)i.push(e.deleteObject({Bucket:a,Key:s}).promise());yield Promise.all(i)}catch(e){}}),this.initDeleteDirectory=(a,o)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s=a.body.data;this.modelChecker(s,!0)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,a),t=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",a,s),e&&t?("aws"===this.storageType?yield this.deleteAWSFolderContent(""+s.bucketName,`${s.assetCollectionName}/${s.assetParentId}/`):(i=this.uploadAdmin.storage().bucket().file(`${s.assetCollectionName}/${s.assetParentId}/`),yield this.deleteGoogleFolderContents(i)),o.send({success:!0})):o.status(400).json({err:"Invalid Security Configuration"})):o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.initGet=(n,r)=>__awaiter(this,void 0,void 0,function*(){try{var{bucketName:e,assetCollectionName:t,assetParentId:i,fileName:s}=n.params;if("aws"===this.storageType){const a=new this.uploadAdmin.S3,o={Bucket:e,Key:t+`/${i}/`+s};a.headObject(o,i=>__awaiter(this,void 0,void 0,function*(){var e,t;i&&"NotFound"===i.code?r.status(404).send({message:"File not found"}):(t=(e=yield a.getObject(o).promise()).ContentType,r.set("Content-Disposition",`attachment; filename="${o.Key}"`),r.set("Content-Type",t),r.send(e.Body))}))}}catch(e){r.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/upload",this.lib.multer.single("file"),(e,t)=>{this.initUpload(e,t,"create")}),e.post("/update",this.lib.multer.single("file"),(e,t)=>{this.initUpload(e,t,"update")}),e.post("/delete",this.initDelete),e.post("/deleteDirectory",this.initDeleteDirectory),e.get("/get/:bucketName/:assetCollectionName/:assetParentId/:fileName/:token",this.initGet),e},this.uploadAdmin=e,this.isProd=t,this.config=i,this.lib=s,this.storageType=null!=a?a:"firebase"}}exports.UploadWrapper=UploadWrapper;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,l){return new(r=r||Promise)(function(i,t){function s(e){try{o(l.next(e))}catch(e){t(e)}}function a(e){try{o(l.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(s,a)}o((l=l.apply(e,n||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.UploadWrapper=void 0;const QueryModel_1=require("../model/QueryModel"),axios_1=__importDefault(require("axios")),mime_1=__importDefault(require("mime"));class UploadWrapper{constructor(e,t,i,s,a){this.uploadAdmin="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.storageType="firebase",this.modelChecker=(e,t)=>!(!e.assetCollectionName||!e.assetParentId||!t&&!e.assetFileName),this.initUpload=(d,c,u)=>__awaiter(this,void 0,void 0,function*(){try{const l=d.body.data;if(this.modelChecker(l)&&(d.file||l.downloadLink)){var e=(0,QueryModel_1.checkBaseConfig)(this.config,d),t=(0,QueryModel_1.checkOpsConfig)(this.config,u,d,l);if(e&&t){const n=this.lib.randomUUID();if("aws"===this.storageType){var i,s=(n,r)=>new Promise((a,o)=>__awaiter(this,void 0,void 0,function*(){var e="buffer"===n,t=new this.uploadAdmin.S3;let i;e||(s=d.file.originalname.split(".").pop(),i="mbtiles"===s?"application/vnd.mapbox-vector-tile":mime_1.default.getType(s)||d.file.mimetype);var s={Bucket:`${l.bucketName}/${l.assetCollectionName}/`+l.assetParentId,Key:e?l.assetFileName:d.file.originalname,Body:e?r.data:d.file.buffer,ContentType:e?r.headers["content-type"]:i};t.upload(s,function(e){e?o(e):a("aws")})}));l.downloadLink?(i=yield(0,axios_1.default)({method:"GET",url:l.downloadLink,responseType:"arraybuffer"})).data&&(yield s("buffer",i)):yield s("file")}else{const r=this.uploadAdmin.storage().bucket();var a,o=(a,o)=>new Promise((i,s)=>__awaiter(this,void 0,void 0,function*(){var e="buffer"===a,t={contentType:e?o.headers["content-type"]:d.file.mimetype,customMetadata:{"file-name":"buffer"===a?l.assetFileName:d.file.originalname},metadata:{firebaseStorageDownloadTokens:n}},t=r.file(`${l.assetCollectionName}/${l.assetParentId}/`+l.assetFileName).createWriteStream({metadata:t});t.end(e?o.data:d.file.buffer),t.on("error",s),t.on("finish",i)}));l.downloadLink?(a=yield(0,axios_1.default)({method:"GET",url:l.downloadLink,responseType:"arraybuffer"})).data&&(yield o("buffer",a)):yield o("file")}c.send({data:n})}else c.status(400).json({err:"Invalid Security Configuration"})}else c.status(400).json({err:"Invalid Fields"})}catch(e){c.status(400).json({err:e})}}),this.initDelete=(o,n)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,a=o.body.data;this.modelChecker(a)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,o),t=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",o,a),e&&t?("aws"===this.storageType?(i=new this.uploadAdmin.S3,s={Bucket:`${a.bucketName}/${a.assetCollectionName}/`+a.assetParentId,Key:a.assetFileName},yield i.deleteObject(s).promise()):yield this.uploadAdmin.storage().bucket().file(`${a.assetCollectionName}/${a.assetParentId}/`+a.assetFileName).delete(),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})}}),this.deleteGoogleFolderContents=o=>__awaiter(this,void 0,void 0,function*(){try{var e={prefix:o.name,autoPaginate:!1},[t]=yield this.uploadAdmin.storage().bucket().getFiles(e),i=[];for(const s of t)i.push(s.delete());for(const a of t)a.name.endsWith("/")&&i.push(this.deleteGoogleFolderContents(a));yield Promise.all(i)}catch(e){}}),this.deleteAWSFolderContent=(a,o)=>__awaiter(this,void 0,void 0,function*(){try{var e=new this.uploadAdmin.S3,t=(yield e.listObjectsV2({Bucket:a,Prefix:o}).promise()).Contents.map(e=>e.Key),i=[];for(const s of t)i.push(e.deleteObject({Bucket:a,Key:s}).promise());yield Promise.all(i)}catch(e){}}),this.initDeleteDirectory=(a,o)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s=a.body.data;this.modelChecker(s,!0)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,a),t=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",a,s),e&&t?("aws"===this.storageType?yield this.deleteAWSFolderContent(""+s.bucketName,`${s.assetCollectionName}/${s.assetParentId}/`):(i=this.uploadAdmin.storage().bucket().file(`${s.assetCollectionName}/${s.assetParentId}/`),yield this.deleteGoogleFolderContents(i)),o.send({success:!0})):o.status(400).json({err:"Invalid Security Configuration"})):o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.initGet=(n,r)=>__awaiter(this,void 0,void 0,function*(){try{const{bucketName:e,assetCollectionName:t,assetParentId:i,fileName:s}=n.params;if("aws"===this.storageType){const a=new this.uploadAdmin.S3,o={Bucket:e,Key:t+`/${i}/`+s};a.headObject(o,e=>__awaiter(this,void 0,void 0,function*(){if(e&&"NotFound"===e.code)r.status(404).send({message:"File not found"});else{var t=yield a.getObject(o).promise(),i=s.split(".").pop();let e;e="mbtiles"===i?"application/vnd.mapbox-vector-tile":mime_1.default.getType(i)||t.ContentType,r.set("Content-Type",e),r.send(t.Body)}}))}}catch(e){r.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return this.lib.cors&&e.use(this.lib.cors()),e.post("/upload",this.lib.multer.single("file"),(e,t)=>{this.initUpload(e,t,"create")}),e.post("/update",this.lib.multer.single("file"),(e,t)=>{this.initUpload(e,t,"update")}),e.post("/delete",this.initDelete),e.post("/deleteDirectory",this.initDeleteDirectory),e.get("/get/:bucketName/:assetCollectionName/:assetParentId/:fileName",this.initGet),e},this.uploadAdmin=e,this.isProd=t,this.config=i,this.lib=s,this.storageType=null!=a?a:"firebase"}}exports.UploadWrapper=UploadWrapper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blixify-server",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "license": "MIT",
5
5
  "main": "dist/apis/index.js",
6
6
  "private": false,
@@ -34,8 +34,8 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "aws-sdk": "^2.1423.0",
38
37
  "axios": "^1.4.0",
38
+ "mime": "^3.0.0",
39
39
  "moment": "^2.29.4"
40
40
  },
41
41
  "devDependencies": {
@@ -43,6 +43,7 @@
43
43
  "@types/node": "^17.0.35",
44
44
  "@typescript-eslint/eslint-plugin": "^5.25.0",
45
45
  "@typescript-eslint/parser": "^5.25.0",
46
+ "aws-sdk": "^2.1432.0",
46
47
  "body-parser": "^1.20.0",
47
48
  "branch-naming-check": "^1.0.2",
48
49
  "commit-message-validator": "^1.0.2",